Re: Dynamic Object Type Fields

2016-07-30 Thread OderWat
+1 to what Krux02 said. If you use Nim like that you don't gain very much over Python. It will not be faster (as Nim and Python both need the work to be done at runtime) and you won't avoid errors and lose easier reasoning and refactoring possibilities because the compiler can't check the types

Re: Dynamic Object Type Fields

2016-07-30 Thread Krux02
Ok, I get the problem here. At first I thought you would need an interface object to interact with languages like Python, where you do not know the fields. But you what you actually want is to treat Nim like as if it is Python, and all I can tell you that is a bad idea, and don't do that. You sh

Re: Dynamic Object Type Fields

2016-07-30 Thread everlast
@flyx I guess it's not NEEDED because I can just store it in a table but after using Python year after year it just seems like something natural. The "solution" based on posts above is: import tables template `.?`*[T](a: T, f: untyped): untyped = a[astToStr(f)]

Re: Dynamic Object Type Fields

2016-07-30 Thread flyx
This is not possible by design. type test* = object Here, you declare an object that has no fields. var t = test() Here, you instantiate this object. `t` has the type `test`. var t.name = "kek" The compiler now looks at `t`'s type an

Re: Dynamic Object Type Fields

2016-07-29 Thread Stefan_Salewski
> So soemthing like Python's setattr() doesn't exist then? I think when you want support for dynamic runtime attributes, you have to prepare for it in a compiled language. For example you can add a field of type seq or table to your object and a proc for adding data to this field. Of course in

Re: Dynamic Object Type Fields

2016-07-29 Thread everlast
So soemthing like Python's setattr() doesn't exist then?

Re: Dynamic Object Type Fields

2016-07-29 Thread OderWat
Afaik it is not. You could use a JSON Object for example or a Table and use "experimental" pragma for dot overloading (in devel) or better using your own operator like `.?` (which was already be planned to be as being part of the compiler to allow: `foo.?bar` being equal to `foo[bar]` afair :)

Dynamic Object Type Fields

2016-07-29 Thread everlast
Is this possible in nim? An example of what I mean: type test* = object var t = test() var t.name = "kek" #This would fail to compile