Re: Is D suitable for my latest project?
On Tuesday, 8 September 2015 at 21:51:03 UTC, wobbles wrote: "Previously undefined". As far as I know, this is impossible in D. Thr compiler has to know how much memory to allocate/request and it has to know that at compiletime (else it wouldn't be the compiler!) There was also this: http://rosettacode.org/wiki/Add_a_variable_to_a_class_instance_at_runtime#D That made me think I could emulate the functionality I need.
Re: Is D suitable for my latest project?
On Wednesday, 9 September 2015 at 09:14:30 UTC, Atila Neves wrote: So, if your use-case depends on information from the file-system, user interaction, networking, etc. then your only choice is to generate text files with D code and compile it. If, on the other hand, it's all defined by the code you write, then D has excellent compile-time code generation tools at your disposal. Thanks for the in depth reply. Unfortunately, yes, my use case depends on user input so definitions will not be known at compiletime. I'm keen to learn D though so I think I'm going to try and make it work with dynamically compiling and loading libraries.
Re: Is D suitable for my latest project?
On Wednesday, 9 September 2015 at 08:24:06 UTC, Kagamin wrote: As I understand, you wanted to build an AST tree and format it to string? Thanks again. So I can build an AST and convert it to full D source from that? I think that's what i'm likely going need to do.
Re: Is D suitable for my latest project?
On Tuesday, 8 September 2015 at 21:51:03 UTC, wobbles wrote: "Previously undefined". As far as I know, this is impossible in D. Thr compiler has to know how much memory to allocate/request and it has to know that at compiletime (else it wouldn't be the compiler!) http://wiki.dlang.org/Dynamic_typing This is what I saw that made me think that I could. Have had another closer look and I do believe it's possible.
Re: Is D suitable for my latest project?
On Monday, 7 September 2015 at 07:57:07 UTC, Kagamin wrote: On Sunday, 6 September 2015 at 15:15:03 UTC, chris stevens wrote: I guess you're right it wouldn't be too difficult to do it all using strings. The code generation I'd done before in c# I'd used some 3rd person library where you build up an object model rather than using strings. Maybe with dparse you can construct an AST and later convert it to string. Thanks for the reply Kagamin, just had a quick look at dparse and not sure how I could use it in the way you describe. Any examples of this?
Re: Is D suitable for my latest project?
On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote: You have Object.factory for this. You can also use a custom factory based on string comparison. (with some: static if(condition) return new This; else static if(otherCondition) return new That; etc). I just had a look at Object.factory and this isn't actually what I wanted. I was looking for something that would allow me to create new (previously undefined) classes in D at runtime that I could then use with Object.factory to create instances of. I think I can do this with Variants and dynamic, is this possible? Or is there another way?
Re: Is D suitable for my latest project?
Thanks so much for your reply. On Sunday, 6 September 2015 at 14:45:45 UTC, BBasile wrote: if you mean to generate code as string, writing them to a file, of course it will work in D. I guess you're right it wouldn't be too difficult to do it all using strings. The code generation I'd done before in c# I'd used some 3rd person library where you build up an object model rather than using strings. Ok, all sounds good. Looks like I'm going to be coding in D.:)
Re: Is D suitable for my latest project?
On Sunday, 6 September 2015 at 14:36:53 UTC, chris stevens wrote: - dynamic compilation of code files at runtime I guess I could just invoke the compiler from my code for this? I would also like to be able to load this compiled code into the current process. This probably can be achieved using a simple loadLibrary command right?
Is D suitable for my latest project?
Hi All, I am considering using D for my latest project and there are a few features I would like and am not entirely sure at this point whether D has them. They are: - dynamic creation of classes/structs at runtime (think I can emulate this with variants/dynamic) - dynamic compilation of code files at runtime - some basic code creation tools Are the above possible? Thanks for any help, Chris Stevens