Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
On Friday, 12 September 2025 at 21:46:51 UTC, monkyyy wrote: On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it. (If you've ever tried reading the source code for Glibc, or the s

Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
I'm not clear about why 'class'es are on the 'avoid' list. D has excellent support for Single inheritance, Interfaces, Design by Contract (DbC), GC, etc. I'm aware that there is a small run time cost for selecting the right virtual method. To reduce this cost, one must final-ize methods that

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 23:58:57 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 21:46:51 UTC, monkyyy wrote: On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it.

Re: Discuss: Classes are well supported in D, with Design by Contracts. Shouldn't we take advantage of that?

2025-09-12 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 13 September 2025 at 00:43:38 UTC, Brother Bill wrote: I'm not clear about why 'class'es are on the 'avoid' list. D has excellent support for Single inheritance, Interfaces, Design by Contract (DbC), GC, etc. I'm aware that there is a small run time cost for selecting the right vi

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 20:10:25 UTC, H. S. Teoh wrote: Phobos code was legendary for being a standard library that didn't make your head hurt when you read it. (If you've ever tried reading the source code for Glibc, or the standard library for almost any other language, really, you'll

Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
Is is possible to 'disable' .init for a struct? source/app.d ``` import std.stdio; void main() { // Can still create Archive with an empty filename. We can't have that. auto noDefault = Archive.init; writefln("fileName: [%s]", noDefault.fileName); } // adding a constructor au

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 12, 2025 at 03:41:15PM +, realhet via Digitalmars-d-learn wrote: > On Friday, 12 September 2025 at 15:28:58 UTC, Monkyyy wrote: > > On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: > > > Hi, > > > > > > ```d > > > import std; > > > > > > [...] > > > > It's seeing the

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 12, 2025 at 06:19:46PM +, Brother Bill via Digitalmars-d-learn wrote: [...] > As a newbie to D, really trying to understand it, I am merely trying > to uncover how to effectively use D. When Programming in D book, page > 292, section 52.4 talks about 'postblit', it states: "If the

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 18:19:46 UTC, Brother Bill wrote: Is there a 'style' guide for D, such as: Do this, Don't do that, avoid this, etc.? Someone will link the "offical" style guide, but thats nothing id follow "There are these features in the language, but you should avoid the

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Brother Bill via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:38:15 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:31:37 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 15:24:46 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 12 September 2025 at 13:27:53 UTC, realhet wrote: (x); <- Is not a construct that comes to my mind as useful, but this was it. This forces the mixin to expect an expression and not a statement. Thanks for sharing it! - I did not know this works. :)

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 12:23:21 UTC, Nick Treleaven wrote: On Friday, 12 September 2025 at 09:17:10 UTC, realhet wrote: On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: I did a complete 'martix' of these com

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 09:55:01 UTC, IchorDev wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D You will have to start writing much weirder code than this to Yea, I don't think I dare to do such crazy things, like an lambda in an UDA

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:28:58 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; [...] It's seeing the eof of the mix file no? This is the smallest example so far: ```d import std; void main() { ( mixin("(()=>1)()") ); //i

Re: Preventing .init for Archive struct, Programming in D, page 295

2025-09-12 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 15:31:37 UTC, Brother Bill wrote: On Friday, 12 September 2025 at 15:24:46 UTC, Monkyyy wrote: On Friday, 12 September 2025 at 15:20:38 UTC, Brother Bill wrote: Is is possible to 'disable' .init for a struct? No (and honestly it's bad style to break the constru

Re: Is RDTSC pure?

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Friday, 12 September 2025 at 14:48:43 UTC, Kagamin wrote: malloc is weakly pure, because it returns mutable pointer. The difference is when you call it from strongly pure function, then it doesn't matter, how many times malloc was called. And if the compiler tries to memoise it?

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Monkyyy via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; [...] It's seeing the eof of the mix file no?

Re: Is RDTSC pure?

2025-09-12 Thread Kagamin via Digitalmars-d-learn
malloc is weakly pure, because it returns mutable pointer. The difference is when you call it from strongly pure function, then it doesn't matter, how many times malloc was called.

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 12 September 2025 at 09:17:10 UTC, realhet wrote: On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, thanks for quick answer! When I turn the string mixin into a statement by putting a `;` at its end, th

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D You will have to start writing much weirder code than this to find compiler bugs in D because when a bug is fixed, a new test is created to make sure it doesn't regress. Surface-level features are usu

Re: Placement new and @trusted

2025-09-12 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 11 September 2025 at 08:06:17 UTC, IchorDev wrote: But that's the thing: all I want is to construct objects into *freshly-allocated*, *uninitialised memory*; so my desired use-case has a safe interface and can therefore be marked `@trusted`. However the constructor is a wildcard, s

Is RDTSC pure?

2025-09-12 Thread IchorDev via Digitalmars-d-learn
Recently I wanted to write a pure function that returns an unpredictable number, so I decided to use RDTSC (and any equivalent instruction for other CPU architectures) to do this, since the compiler allows RDTSC to be marked as `pure`. However, in the end I discarded this idea because I figured

Re: Placement new and @trusted

2025-09-12 Thread IchorDev via Digitalmars-d-learn
On Thursday, 11 September 2025 at 17:16:35 UTC, Paul Backus wrote: ```d void inferSystem() @system pure nothrow @nogc {} T* example(T)() { static if (!isSafe!(() { new T(); }) inferSystem(); return (() @trusted => new (new void[](T.sizeof)) T())(); } ``` Unfortunately that woul

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Dejan Lekic via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Is this a feature or a bug? :D Is there a way to make this processing_and_optional_returning thing better? It is a bug in your code. Change line 6 to ```d (){ val += 1; return val; }(); ``` After the added `;` it should wo

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:44:47 UTC, Stefan Koch wrote: On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, thanks for quick answer! When I turn the string mixin into a statement by putting a `;` at its end, the enum bla = `(){return 4;}();` `mixin(bla);` Case works p

Re: When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 12 September 2025 at 08:36:42 UTC, realhet wrote: Hi, ```d import std; void main() { int val = 4; enum prog = q{ (){ val += 1; return val; }() }; //mixin(prog); // auto dummy = mixin(prog); //Must capture the return value, otherwise it hallucinates EOF.

When not capturing the return value of a string mixin expression, I get "found `End of File` when expecting `;`"

2025-09-12 Thread realhet via Digitalmars-d-learn
Hi, ```d import std; void main() { int val = 4; enum prog = q{ (){ val += 1; return val; }() }; //mixin(prog); // auto dummy = mixin(prog); //Must capture the return value, otherwise it hallucinates EOF. writeln(val); } ``` When uncommentingmixin(prog); It