Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread zabruk via Digitalmars-d-learn
On Sunday, 7 April 2019 at 03:32:45 UTC, Alex wrote: just execute them at CT if possible(and the possibility simply is if the inputs are known at CT). imho, Bastiaan Veelo want to say about citate above: not just "if possible", but "only if needed and possible"

Re: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-06 Thread Alex via Digitalmars-d-learn
On Sunday, 7 April 2019 at 05:36:27 UTC, Vladimir Panteleev wrote: On Sunday, 7 April 2019 at 05:24:38 UTC, Alex wrote: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()` mixin(`import `~moduleName!(T)~`;`); mixin(`alias

Re: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-06 Thread Vladimir Panteleev via Digitalmars-d-learn
On Sunday, 7 April 2019 at 05:24:38 UTC, Alex wrote: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()` mixin(`import `~moduleName!(T)~`;`); mixin(`alias X = T.`~name~`;`); super.Reflect!(X); I realize X

Re: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 7 April 2019 at 05:24:38 UTC, Alex wrote: Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()` mixin(`import `~moduleName!(T)~`;`); mixin(`alias X = T.`~name~`;`); super.Reflect!(X); I realize X

Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()`

2019-04-06 Thread Alex via Digitalmars-d-learn
Error: template instance `Reflect!(type)` cannot use local `type` as parameter to non-global template `Reflect(Ts...)()` mixin(`import `~moduleName!(T)~`;`); mixin(`alias X = T.`~name~`;`); super.Reflect!(X); I realize X is local but I'm trying to figure out why it can't be

alias sequences of sequences

2019-04-06 Thread Alex via Digitalmars-d-learn
Is there any way to get sequences of sequences? Using RT, I have to use strings [[`string`, `0`], ...] when it would be much better to use [[string, 0], ...] Ideally it wouldn't add so much overhead that it defeats the purpose.

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-06 Thread Alex via Digitalmars-d-learn
On Saturday, 6 April 2019 at 13:03:31 UTC, Adam D. Ruppe wrote: On Saturday, 6 April 2019 at 12:20:28 UTC, Alex wrote: static foreach (f; typeof(__traits(getOverloads, T, m))) Why are you using typeof here? I don't know, I want to say I copied that code from somewhere but it might have been

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread Alex via Digitalmars-d-learn
On Saturday, 6 April 2019 at 14:59:18 UTC, ag0aep6g wrote: On 06.04.19 16:19, Alex wrote: That is CTFE is CT RTFE where runtime functions are executed at compile time when the inputs are CT. You may have the right idea, but the last part of that sentence is wrong/misleading. CTFE happens when

Re: == comparison of string literals, and their usage

2019-04-06 Thread diniz via Digitalmars-d-learn
Le 06/04/2019 à 21:47, lithium iodate via Digitalmars-d-learn a écrit : On Saturday, 6 April 2019 at 15:35:22 UTC, diniz wrote: So, I still could store and use and compare string pointers myself [1], and get valid results, meaning: pointer equality implies (literal) string equality. Or am I wro

Re: What's the correct way to interface with a intptr_t?

2019-04-06 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? The correct equivalent is `intptr_t` from `core.stdc.stdint`.

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread Bastiaan Veelo via Digitalmars-d-learn
On Saturday, 6 April 2019 at 12:06:22 UTC, Robert M. Münch wrote: The idea is, that I can write a string (or maybe even a scope block?) in my DSL and use a CTFE grammer to transpile the code. Are you aware of Pegged[1]? It’s for exactly that. [1] http://code.dlang.org/packages/pegged

Re: What's the correct way to interface with a intptr_t?

2019-04-06 Thread Alex via Digitalmars-d-learn
On Saturday, 6 April 2019 at 19:31:15 UTC, Robert M. Münch wrote: I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? I suppose, ptrdiff_t is. https://dlang.org/spec/type.html#ptrdiff_t https://dlang.org/spec/portability.html#32_to_64bi

Re: == comparison of string literals, and their usage

2019-04-06 Thread lithium iodate via Digitalmars-d-learn
On Saturday, 6 April 2019 at 15:35:22 UTC, diniz wrote: So, I still could store and use and compare string pointers myself [1], and get valid results, meaning: pointer equality implies (literal) string equality. Or am I wrong? The point is, the parser, operating on an array of prescanned lexeme

What's the correct way to interface with a intptr_t?

2019-04-06 Thread Robert M. Münch via Digitalmars-d-learn
I have a C interface that uses a parameter of type intptr_t. Wondering if size_t is the correct D equivalent? -- Robert M. Münch http://www.saphirion.com smarter | better | faster

Re: Problems instantiating template class

2019-04-06 Thread Mek101 via Digitalmars-d-learn
On Saturday, 6 April 2019 at 18:08:31 UTC, Mek101 wrote: On Saturday, 6 April 2019 at 17:44:25 UTC, Nicholas Wilson wrote: Hmm, import std.traits; class WeightedRandom(T, W = float) if(isNumeric!W) { // Fields private W[T] _pairs; // The total sum of all the weights;

Re: Problems instantiating template class

2019-04-06 Thread Mek101 via Digitalmars-d-learn
On Saturday, 6 April 2019 at 17:44:25 UTC, Nicholas Wilson wrote: Hmm, import std.traits; class WeightedRandom(T, W = float) if(isNumeric!W) { // Fields private W[T] _pairs; // The total sum of all the weights; private W _probabilities; /// Code...

Re: Problems instantiating template class

2019-04-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 6 April 2019 at 17:30:45 UTC, Mek101 wrote: I'm rewriting from C# a small library of mine to practice with D. I have a class: class WeightedRandom(T, W = float) if(isNumeric!W) { // Fields private W[T] _pairs; // The total sum of all the weights;

Problems instantiating template class

2019-04-06 Thread Mek101 via Digitalmars-d-learn
I'm rewriting from C# a small library of mine to practice with D. I have a class: class WeightedRandom(T, W = float) if(isNumeric!W) { // Fields private W[T] _pairs; // The total sum of all the weights; private W _probabilities; /// Code... } An

Re: == comparison of string literals, and their usage

2019-04-06 Thread diniz via Digitalmars-d-learn
Le 06/04/2019 à 16:07, AltFunction1 via Digitalmars-d-learn a écrit : On Friday, 5 April 2019 at 14:49:50 UTC, diniz wrote: Hello, Since literal strings are interned (and immutable), can I count on the fact that they are compared (==) by pointer? No. "==" performs a full array comparison and

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread ag0aep6g via Digitalmars-d-learn
On 06.04.19 16:19, Alex wrote: That is CTFE is CT RTFE where runtime functions are executed at compile time when the inputs are CT. You may have the right idea, but the last part of that sentence is wrong/misleading. CTFE happens when the result is required at CT. The inputs must be available

Re: Does new X() return a pointer or not?

2019-04-06 Thread faissaloo via Digitalmars-d-learn
Thanks alot everyone for your replies, this makes sense now.

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread Alex via Digitalmars-d-learn
On Saturday, 6 April 2019 at 12:06:22 UTC, Robert M. Münch wrote: I like the idea of DSL which are transpiled into the target language that gets compiled or are interpreted at run-time. Since D is compiled, I would like to transpile the DSL to D at compile-time. The idea is, that I can write

Re: CTFE & code generators based on PEG grammars?

2019-04-06 Thread Seb via Digitalmars-d-learn
On Saturday, 6 April 2019 at 12:06:22 UTC, Robert M. Münch wrote: I like the idea of DSL which are transpiled into the target language that gets compiled or are interpreted at run-time. Since D is compiled, I would like to transpile the DSL to D at compile-time. The idea is, that I can write

Re: == comparison of string literals, and their usage

2019-04-06 Thread AltFunction1 via Digitalmars-d-learn
On Friday, 5 April 2019 at 14:49:50 UTC, diniz wrote: Hello, Since literal strings are interned (and immutable), can I count on the fact that they are compared (==) by pointer? No. "==" performs a full array comparison and "is" is apparently simplified at compile time. In the compiler there'

Re: Does new X() return a pointer or not?

2019-04-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 6 April 2019 at 13:34:06 UTC, faissaloo wrote: ComponentChild is a derived class of Component. This means it is not a Component*. new X returns a pointer if X is a struct, but for classes, it is not. Are objects automatically assumed to be pointers? Yeah, for classes.

Re: Does new X() return a pointer or not?

2019-04-06 Thread rikki cattermole via Digitalmars-d-learn
On 07/04/2019 2:34 AM, faissaloo wrote: Are objects automatically assumed to be pointers? It is a reference. Which is a fancy way of saying pointer under the hood. Just don't do pointer arithmetic with it ;) Object* means a pointer to a class object reference. Which isn't what you were inten

Does new X() return a pointer or not?

2019-04-06 Thread faissaloo via Digitalmars-d-learn
I have the following function static Component* constructComponent(int value) { return (new ComponentChild(value)); } ComponentChild is a derived class of Component. However, I get told that ComponentChild cannot be converted to Component*. I'm confused here, doe

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 6 April 2019 at 12:20:28 UTC, Alex wrote: static foreach (f; typeof(__traits(getOverloads, T, m))) Why are you using typeof here? probably 90% of the mixins are of the form mixin(`Protection = __traits(getProtection, (`~T.stringof~`).`~name~`);`); Try following this rule: N

Re: Overloads not returning appropriate info. [Field reflunkory]

2019-04-06 Thread Alex via Digitalmars-d-learn
On Friday, 5 April 2019 at 15:38:18 UTC, Adam D. Ruppe wrote: BTW `T.stringof` is usually a bug waiting to happen. You are using mixin in a lot of places where you shouldn't be and this is going to lead to name conflicts, import problems, and more. Just use `T`. If you need a member, use __tr

CTFE & code generators based on PEG grammars?

2019-04-06 Thread Robert M. Münch via Digitalmars-d-learn
I like the idea of DSL which are transpiled into the target language that gets compiled or are interpreted at run-time. Since D is compiled, I would like to transpile the DSL to D at compile-time. The idea is, that I can write a string (or maybe even a scope block?) in my DSL and use a CTFE gr