Ah, you probably want `declared` instead of `declaredInScope`. The latter only
works for the immediately enclosing scope and not the ones above it. The
documentation may not be very clear on that
[https://nim-lang.org/docs/system.html#declared%2Cuntyped](https://nim-lang.org/docs/system.html#dec
You could do it by wrapping in a template
import macros
template foo(body: untyped) =
block:
let inFoo {. inject, used .} = true
body
template bar(body: untyped) =
block:
let inBar {. inject, used .} = true
body
p
You can also use AST based overloading
[https://nim-lang.org/docs/manual_experimental.html#ast-based-overloading](https://nim-lang.org/docs/manual_experimental.html#ast-based-overloading)
(which isn't actually experimental even though it appears there). In this case
all the overloads will need t
Is there a reason finalizers need to be set in `new` as opposed to following
destructors?
proc `=finalize`(x: T) = ...
Run
If you want to set them at the type definition you can use custom annotations:
[https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-custom-annotations](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-custom-annotations)
You could use overloaded templates
type
MsgAlpha = object
id: int
x, y: int
url: string
MsgBeta = object
id: int
resource: string
template msgId(x: typedesc[MsgAlpha]): untyped = 1
template msgId(x: typedesc[MsgB
You can simply leave off the generic parameters and use it as a typeclass.
template iteratorsArithmetics*(name: untyped): untyped =
proc `+`*[T:name](it: T, offset: int): T
{.importcpp: "# + #"}
proc `-`*[T:name](it: T, offset: int): T
{.importcpp: "# - #"
Actually, the allocator fixes, I think, would only apply to large (>1 GB)
memory use, so that may not be relevant here. I'm sorry if I lead you down the
wrong path.
Can you try testing with the Nim devel branch? Some allocator bugs have been
fixed there.
Here's a related thread:
[https://forum.nim-lang.org/t/2201](https://forum.nim-lang.org/t/2201)
Is there a way to get a CommentStmt out of a TypeDef? In the example below,
`comment 3` doesn't show up in the AST tree, but is there in the repr.
import macros
macro dump(x: typed): untyped =
echo x.treerepr
echo x.repr
newEmptyNode()
dump:
You need to put the compiler arguments before the source file otherwise it
takes them to be arguments to the binary for the run command. This should work
nim --run c -o:../bin/program main.nim
I've been using them in my project for a while now. I have a simple wrapper for
OpenMP [here](https://github.com/jcosborn/qex/blob/master/src/omp.nim) and some
SIMD wrappers [here](https://github.com/jcosborn/qex/tree/master/src/simd).
The SIMD stuff is still a bit of a mess now, bu
Yes, 'any' is a generic (typeclass). Your object should probably be defined
like this
type item[T] = object
value: T
next: ptr item[T]
Likewise '<' is an overloaded proc, so not a specific proc that you can pass to
a function. Also, you don't need to specify 'ptr'
In the case of `proc f(x: Has[seq[any]])`, could you first try matching against
the generic `Has[T]`, let the concept body define `T`, then extract its value
and compare that against `seq[any]` to see if it matches? At that point if the
type constraint was `Has[seq[S]]` you could match to bind `
I don't know if this helps, but wouldn't
type Container[T] = concept c
type T = type(get(c, 0))
be more natural? Plus we could extend it to allow static parameters
type Container[N,T] = concept c
const N = c.len
type T = type(get(c, 0))
16 matches
Mail list logo