Re: Explain function syntax

2025-09-21 Thread user1234 via Digitalmars-d-learn
On Monday, 22 September 2025 at 00:27:09 UTC, Steven Schveighoffer wrote: On Sunday, 21 September 2025 at 20:33:11 UTC, user1234 wrote: On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: Looking at historical compilers, the `alias ... =` syntax was added in 2.087.0. B

Re: Explain function syntax

2025-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On Sunday, 21 September 2025 at 20:33:11 UTC, user1234 wrote: On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax. Actually D has a syntax

Re: Explain function syntax

2025-09-21 Thread user1234 via Digitalmars-d-learn
On Saturday, 20 September 2025 at 02:36:47 UTC, Steven Schveighoffer wrote: What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax. Actually D has a syntax to expression function types: ```d alias FT = void(int); void

Re: Explain function syntax

2025-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 9/18/25 10:18 PM, Steven Schveighoffer wrote: > On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: >> // Not a delegate: >> static assert(is (typeof(twice) == function)); > You are mistaking the is expression for a function test with the > function pointer type. I dis

Re: Explain function syntax

2025-09-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 19 September 2025 at 16:58:38 UTC, Ali Çehreli wrote: On 9/18/25 10:18 PM, Steven Schveighoffer wrote: > On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: >> // Not a delegate: >> static assert(is (typeof(twice) == function)); > You are mistaking the is expre

Re: Explain function syntax

2025-09-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thursday, 18 September 2025 at 18:10:13 UTC, Ali Çehreli wrote: As stated by multiple people, most nested functions will be 'delegates'. However, a nested function is a 'function' if it does not touch local scope: ```d void main() { int twice(int i) { return i * 2; } //

Re: Explain function syntax

2025-09-18 Thread Ali Çehreli via Digitalmars-d-learn
As stated by multiple people, most nested functions will be 'delegates'. However, a nested function is a 'function' if it does not touch local scope: void main() { int twice(int i) { return i * 2; } // Not a delegate: static assert(is (typeof(twice) == function)); } Ali

Re: Explain function syntax

2025-09-18 Thread Dejan Lekic via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: In the following from Programming in D, page 483, we use function keyword. I expect that the first int in ``` int function(int); ``` represents the return value. What does the second (int) refer to? Second int is the type

Re: Explain function syntax

2025-09-18 Thread Luna via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: In the following from Programming in D, page 483, we use function keyword. I expect that the first int in ``` int function(int); ``` represents the return value. What does the second (int) refer to? Then there is another ex

Re: Explain function syntax

2025-09-18 Thread kdevel via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: return value => increment + value; // ← compilation ERROR ```d void main() { auto calc = makeCalculator; writeln (calc (1)); } alias Calculator = int function(int); Calculator makeCalculator() {

Re: Explain function syntax

2025-09-17 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: Then there is another example with 'delegate' instead of 'function. ``` import std.stdio; void main() { } alias Calculator = int function(int); Calculator makeCalculator() { int increment = 10; return value

Re: Explain function syntax

2025-09-17 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 17, 2025 at 10:16:50PM +, Brother Bill via Digitalmars-d-learn wrote: > In the following from Programming in D, page 483, we use function keyword. > > I expect that the first int in > ``` > int function(int); > ``` > > represents the return value. > > What does the second (int)

Re: Explain function syntax

2025-09-17 Thread monkyyy via Digitalmars-d-learn
On Wednesday, 17 September 2025 at 22:16:50 UTC, Brother Bill wrote: ``` import std.stdio; void main() { } alias Calculator = int function(int); Calculator makeCalculator() { int increment = 10; return value => increment + value; // ← compilation ERROR } ``` function is alm