Re: Templates/Mixin - Is there a way to see expanded source code equivalent?

2025-08-24 Thread monkyyy via Digitalmars-d-learn
On Monday, 25 August 2025 at 02:36:01 UTC, Brother Bill wrote: also just factor it out and unit test it if its complex

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 14:40:36 UTC, Steven Schveighoffer wrote: ```d // solution 1: (preferred) if(auto r = cast(MyInt)result){ writeln(r); }else if(auto r = cast(MyFloat)result){ writeln(r); } // solution 2: if(typeid(result) is typeid(MyInt)){ writeln(cast(MyInt)result); }el

Re: Templates/Mixin - Is there a way to see expanded source code equivalent?

2025-08-24 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 25/08/2025 2:36 PM, Brother Bill wrote: Is there a way to see expanded templates/mixins as the D compile expands it? This would be nice for pedagogical purposes. -mixin= expand and save mixins to file specified by

Templates/Mixin - Is there a way to see expanded source code equivalent?

2025-08-24 Thread Brother Bill via Digitalmars-d-learn
Is there a way to see expanded templates/mixins as the D compile expands it? This would be nice for pedagogical purposes.

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 20:43:15 UTC, Ali Çehreli wrote: I think you went a little further in that section and made the return 'auto ref', which does not (and should not) fail compilation. No. auto ref is only for templates. This is a bug and should not compile. -Steve

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:29:01 UTC, Steven Schveighoffer wrote: ``` import std.stdio; void main() { string * ptrSum = &parenthesized("2 + 3"); string sum = parenthesized("4 * 5"); writefln("ptrSum : %s %s", ptrSum, *ptrSum); writefln("sum: %s", sum); } auto ref s

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Ali Çehreli via Digitalmars-d-learn
On 8/24/25 11:17 AM, Brother Bill wrote: > On Sunday, 24 August 2025 at 17:30:33 UTC, Ali Çehreli wrote: >> In this case, you used the body of a 'ref' function but compiled it as >> 'auto ref'. Please remove 'auto' above. >> >> Ali > > The book has 'auto ref' in "auto ref functions" section. Yes.

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Ali Çehreli via Digitalmars-d-learn
On 8/24/25 11:29 AM, Brother Bill wrote: > Ali, may I have a Yes or No on permission to use your Programming in D > examples that I am expanding for a commercial Udemy course that I will > build. If this forum post is authoritative for you, yes, I give permission. > Also, would now be a good ti

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Brother Bill via Digitalmars-d-learn
On Sunday, 24 August 2025 at 17:30:33 UTC, Ali Çehreli wrote: First, thank you for reading the book and raising so many issues. Very much appreciated! Ali Ali, may I have a Yes or No on permission to use your Programming in D examples that I am expanding for a commercial Udemy course that

Re: How to make a slow compile

2025-08-24 Thread monkyyy via Digitalmars-d-learn
On Sunday, 24 August 2025 at 13:59:46 UTC, Andrey Zherikov wrote: On Wednesday, 20 August 2025 at 15:33:45 UTC, monkyyy wrote: once again dconf contains people who talk about compile speed as if it can be slow What are they doing? Even my worse compile time abstraction was O(n^2) or maybe som

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Brother Bill via Digitalmars-d-learn
On Sunday, 24 August 2025 at 17:30:33 UTC, Ali Çehreli wrote: In this case, you used the body of a 'ref' function but compiled it as 'auto ref'. Please remove 'auto' above. Ali The book has 'auto ref' in "auto ref functions" section. Does your book need a change? I'm not sure why we should re

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Ali Çehreli via Digitalmars-d-learn
On 8/24/25 8:03 AM, Brother Bill wrote: > auto ref string parenthesized(string phrase) { > string result = '(' ~ phrase ~ ')'; > writeln("&result: ", &result); > return result; // ← compilation ERROR > } First, thank you for reading the book and raising so many issues. Very m

Re: alias template parameters - opCall caller! example breaks in Programming in D, page 530

2025-08-24 Thread Ali Çehreli via Digitalmars-d-learn
On 8/23/25 7:58 AM, monkyyy wrote: >> https://dlang.org/book/templates_more.html#ix_More%20Templates.alias, >> %20template%20parameter > > why is that education material not showing the fundamental pattern of > `(alias F,T...)(T args)=>F(args)`? The book was written before that pattern was added

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:47:28 UTC, Brother Bill wrote: On Sunday, 24 August 2025 at 15:29:01 UTC, Steven Schveighoffer wrote: I don't know what's happening here, but it seems like a bug. This should not compile (it does for me, despite the comment above). It does compile. I didn't

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Brother Bill via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:29:01 UTC, Steven Schveighoffer wrote: I don't know what's happening here, but it seems like a bug. This should not compile (it does for me, despite the comment above). -Steve It does compile. I didn't change the comment from earlier code. The core question

Re: Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 15:03:12 UTC, Brother Bill wrote: On page 549 of Programming in D, it appears that D supports 'escaping' local variables to the heap, when returning their address. This is similar to Go. Is this what is actually going on? Is this 'safe' to do? ``` &result: AC067AF

Confirm: D escapes auto ref similar to Go language

2025-08-24 Thread Brother Bill via Digitalmars-d-learn
On page 549 of Programming in D, it appears that D supports 'escaping' local variables to the heap, when returning their address. This is similar to Go. Is this what is actually going on? Is this 'safe' to do? ``` &result: AC067AF730 &result: AC067AF730 ptrSum : AC067AF7B0 (2 + 3) sum: (4

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 24 August 2025 at 03:13:38 UTC, David T. Oxygen wrote: The `is_int_or_float()` function has also simplified. Then I need to use another function to get the type of the result of `is_int_or_float()`, so I may write another piece of code like: ```d import std.stdio; string inputing="

Re: How to make a slow compile

2025-08-24 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 20 August 2025 at 15:33:45 UTC, monkyyy wrote: once again dconf contains people who talk about compile speed as if it can be slow What are they doing? Even my worse compile time abstraction was O(n^2) or maybe some awful string concatenation of an entire file; still effectively

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 08:25:56 UTC, H. S. Teoh wrote: On Sun, Aug 24, 2025 at 05:20:06AM +, David T. Oxygen via Digitalmars-d-learn wrote: [...] But I still don't know how to use `is` `__traits`. [...] Operations involving types, such as type comparisons, are usually done only insi

Re: foreach vs static foreach on compile time tuples

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 08:35:57 UTC, Per Nordlöw wrote: Which are the pros and cons of foreach vs static foreach on a compile time tuple in D in terms of compiler performance and resource usage? Does static foreach generate more ast duplications? -- Yes, it will make the compile-time lo

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread user1234 via Digitalmars-d-learn
On Sunday, 24 August 2025 at 08:25:56 UTC, H. S. Teoh wrote: On Sun, Aug 24, 2025 at 05:20:06AM +, David T. Oxygen via Digitalmars-d-learn wrote: [...] But I still don't know how to use `is` `__traits`. [...] Operations involving types, such as type comparisons, are usually done only insi

foreach vs static foreach on compile time tuples

2025-08-24 Thread Per Nordlöw via Digitalmars-d-learn
Which are the pros and cons of foreach vs static foreach on a compile time tuple in D in terms of compiler performance and resource usage? Does static foreach generate more ast duplications?

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Aug 24, 2025 at 05:20:06AM +, David T. Oxygen via Digitalmars-d-learn wrote: [...] > But I still don't know how to use `is` `__traits`. [...] Operations involving types, such as type comparisons, are usually done only inside an `is`-expression. For example: ``` struct MyType { ... }