Re: Is it possible for a macro to know the context it is used?

2020-05-18 Thread jcosborn
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

Re: Is it possible for a macro to know the context it is used?

2020-05-17 Thread jcosborn
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

Re: the "type" of the curly-bracket structure

2019-11-20 Thread jcosborn
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

Re: Some more fun with finalizers

2019-04-13 Thread jcosborn
Is there a reason finalizers need to be set in `new` as opposed to following destructors? proc `=finalize`(x: T) = ... Run

Re: Associating data to types

2019-01-11 Thread jcosborn
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)

Re: Associating data to types

2019-01-10 Thread jcosborn
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

Re: Creating generic procs with a template

2019-01-08 Thread jcosborn
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: "# - #"

Re: Memory usage skyrocketed with nim 0.18.0 (in my async tcp service test)

2018-04-03 Thread jcosborn
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.

Re: Memory usage skyrocketed with nim 0.18.0 (in my async tcp service test)

2018-04-01 Thread jcosborn
Can you try testing with the Nim devel branch? Some allocator bugs have been fixed there.

Re: block expression

2018-01-27 Thread jcosborn
Here's a related thread: [https://forum.nim-lang.org/t/2201](https://forum.nim-lang.org/t/2201)

Getting CommentStmt from TypeDef AST

2017-10-28 Thread jcosborn
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:

Re: Specify directory for binary

2017-06-03 Thread jcosborn
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

Re: OpenMP and SIMD

2017-02-25 Thread jcosborn
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

Re: any type and proc pointer!

2017-02-11 Thread jcosborn
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'

Re: Concept[T] design question

2016-07-29 Thread jcosborn
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 `

Re: Concept[T] design question

2016-07-29 Thread jcosborn
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))