Re: collections of procs[T]()

2018-09-29 Thread mitai
Thank you! this does work: > > type > Data*[T] = object > contents: T > subscribers: seq[proc(d: T)] > > proc createData*[T](t: typedesc[T], c: T): Data[T] = > result = Data[T]() > result.contents = c > result.subscribers = @[] > > pr

Re: collections of procs[T]()

2018-09-29 Thread LeuGim
proc addSubscriber*[T](d: var Data[T], cb: proc(d:T)) = d.subscribers.add(cb) Run A typo `T` for `Data[T]`, and `var` needed for `add`.

Re: collections of procs[T]()

2018-09-29 Thread mitai
Thankyou for your reply @mratsim I tried the following: type Data*[T] = object id: string contents: T subscribers: seq[proc(d: T)] proc addSubscriber*[T](d: T, cb: proc(d:T)) = d.subscribers.add(cb) proc c

Re: collections of procs[T]()

2018-09-29 Thread mratsim
Yes you can, see this for example: [https://github.com/mratsim/nim-rmad/blob/master/src/autograd.nim#L46-L57](https://github.com/mratsim/nim-rmad/blob/master/src/autograd.nim#L46-L57) Note that the proc arity (number of arguments) is part of the type, as is its calling convention (pointer/{.nimc

collections of procs[T]()

2018-09-28 Thread mitai
is there a way to have a collection (seq or better: Tables) of procs with generic types?