Re: CTFE, string mixins & code generation

2020-01-24 Thread Jesse Phillips via Digitalmars-d-learn
On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote: I am looking for a detailed explanation or showcase regarding CTFE and string mixins. I want to play with D a little bit regarding code generation. I would like to have a pseudo-AST, consisting of a few classes, to represent some calc

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 24 January 2020 at 18:43:14 UTC, H. S. Teoh wrote: CTFE in general cannot use global variables. Any state you need must be created inside a CTFE function, and accessed from within that calling context. You *can* assign values produced by CTFE to compile-time symbols via 'enum', but

Re: CTFE, string mixins & code generation

2020-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 24, 2020 at 08:26:50PM +0100, Jacob Carlborg via Digitalmars-d-learn wrote: > On 2020-01-24 19:43, H. S. Teoh wrote: > > > (enums cannot take AA's or class objects as values, also, once > > assigned they are immutable). > > AA enums work. Ah you're right, it's statically-constructed

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jacob Carlborg via Digitalmars-d-learn
On 2020-01-24 19:43, H. S. Teoh wrote: (enums cannot take AA's or class objects as values, also, once assigned they are immutable). AA enums work. Class objects kind of work. One can use static const/immutable instead. The following snippet compiles: class A { int a = 3; } const bar =

Re: CTFE, string mixins & code generation

2020-01-24 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 24, 2020 at 04:21:48PM +, Jan Hönig via Digitalmars-d-learn wrote: > I am looking for a detailed explanation or showcase regarding CTFE and > string mixins. > I want to play with D a little bit regarding code generation. > I would like to have a pseudo-AST, consisting of a few clas

Re: CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
On Friday, 24 January 2020 at 16:59:53 UTC, Marco de Wild wrote: For CTFE: functions should be pure. Therefore you cannot use global or static variables. Constants (enums) are perfectly fine to use though. I don't know the state of the GC and CTFE. I recall that there might be some complexity w

Re: CTFE, string mixins & code generation

2020-01-24 Thread Marco de Wild via Digitalmars-d-learn
On Friday, 24 January 2020 at 16:21:48 UTC, Jan Hönig wrote: I am looking for a detailed explanation or showcase regarding CTFE and string mixins. I want to play with D a little bit regarding code generation. I would like to have a pseudo-AST, consisting of a few classes, to represent some calc

CTFE, string mixins & code generation

2020-01-24 Thread Jan Hönig via Digitalmars-d-learn
I am looking for a detailed explanation or showcase regarding CTFE and string mixins. I want to play with D a little bit regarding code generation. I would like to have a pseudo-AST, consisting of a few classes, to represent some calculation. Think of a loop, some statements, and expressions.