how can i mixin a function as struct or class member function

2022-04-16 Thread mycybyby via Digitalmars-d-learn
for example: function void a(int i) { writeln(i); } auto JSFunction(alias F)() if(isSomeFunction!F) { class S { public ReturnType!F dg(ParameterTypeTuple!F) { mixin(F.body) // what should i do ??? } } } thank you

Re: Should a parser type be a struct or class?

2020-06-18 Thread Meta via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: Should a parser type be a struct or class?

2020-06-18 Thread welkam via Digitalmars-d-learn
Oh an also https://github.com/dlang/dmd/pull/9899

Re: Should a parser type be a struct or class?

2020-06-18 Thread welkam via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 14:32:09 UTC, Adam D. Ruppe wrote: On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: Parser in dmd does even inherit from Lexer. why would a parser ever inherit from a lexer? So you can write nextToken() instead of lexer.nextToken()

Re: Should a parser type be a struct or class?

2020-06-17 Thread user1234 via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: Should a parser type be a struct or class?

2020-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 17, 2020 at 02:32:09PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: > > Parser in dmd does even inherit from Lexer. > > why would a parser ever inherit from a lexer? Because, unlike a regular parser-driven compil

Re: Should a parser type be a struct or class?

2020-06-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 14:24:01 UTC, Stefan Koch wrote: Parser in dmd does even inherit from Lexer. why would a parser ever inherit from a lexer?

Re: Should a parser type be a struct or class?

2020-06-17 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: Should a parser type be a struct or class?

2020-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jun 17, 2020 at 11:50:27AM +, Per Nordlöw via Digitalmars-d-learn wrote: > Should a range-compliant aggregate type realizing a parser be encoded > as a struct or class? Preferably a struct IMO, but see below. > In dmd `Lexer` and `Parser` are both classes. Probably for h

Re: Should a parser type be a struct or class?

2020-06-17 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Re: Should a parser type be a struct or class?

2020-06-17 Thread Simen Kjærås via Digitalmars-d-learn
On Wednesday, 17 June 2020 at 11:50:27 UTC, Per Nordlöw wrote: Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a

Should a parser type be a struct or class?

2020-06-17 Thread Per Nordlöw via Digitalmars-d-learn
Should a range-compliant aggregate type realizing a parser be encoded as a struct or class? In dmd `Lexer` and `Parser` are both classes. In general how should I reason about whether an aggregate type should be encoded as a struct or class?

Re: static immutable and lambdas inside struct or class. Is that bug or not?

2016-08-14 Thread Uranuz via Digitalmars-d-learn
On Sunday, 14 August 2016 at 15:53:21 UTC, ag0aep6g wrote: On 08/14/2016 04:27 PM, Uranuz wrote: [...] Looks like a compiler bug, since it works without the struct: import std.algorithm: map; import std.array: array; import std.typecons: tuple; immutable aaa = [ tuple("1", "one

Re: static immutable and lambdas inside struct or class. Is that bug or not?

2016-08-14 Thread ag0aep6g via Digitalmars-d-learn
On 08/14/2016 04:27 PM, Uranuz wrote: Greatings! I need help with these lines bellow. I don't understand why it doesn't compile. Is it bug somewhere in Phobos or compiler? Or just I wrote smth wrong? //- struct A { import std.algorithm: map; import std.array: array; import std

static immutable and lambdas inside struct or class. Is that bug or not?

2016-08-14 Thread Uranuz via Digitalmars-d-learn
Greatings! I need help with these lines bellow. I don't understand why it doesn't compile. Is it bug somewhere in Phobos or compiler? Or just I wrote smth wrong? //- struct A { import std.algorithm: map; import std.array: array; import std.typecons: tuple;

Re: struct or class

2014-08-24 Thread Kiith-Sa via Digitalmars-d-learn
On Sunday, 24 August 2014 at 11:56:44 UTC, nikki wrote: I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am over

Re: struct or class

2014-08-24 Thread ketmar via Digitalmars-d-learn
On Sun, 24 Aug 2014 11:56:42 + nikki via Digitalmars-d-learn wrote: > Or should I use a class for that AtlasSpriteData? > reading about it I get the impression everytime I'll look up data > from that dictionary data will get copied ? p.s. this will not copy: auto sd = "mysprite00" in dic

Re: struct or class

2014-08-24 Thread ketmar via Digitalmars-d-learn
On Sun, 24 Aug 2014 11:56:42 + nikki via Digitalmars-d-learn wrote: > Or should I use a class for that AtlasSpriteData? > reading about it I get the impression everytime I'll look up data > from that dictionary data will get copied ? this will copy: auto sd = dict[0]; this will copy:

Re: struct or class

2014-08-24 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 24 August 2014 at 11:56:44 UTC, nikki wrote: I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am over

Re: struct or class

2014-08-24 Thread Rikki Cattermole via Digitalmars-d-learn
On 24/08/2014 11:56 p.m., nikki wrote: I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am overthinking it. Here

struct or class

2014-08-24 Thread nikki via Digitalmars-d-learn
I come from languages that don't offer structs, I have this json load function that has to keep some data and intuitively I've written a struct, I've read about the differences, heap vs stack, value vs reference, but know I think i am overthinking it. Is this decent: bool loadFromFile