5 days ago

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 expression for a function test with
the
function pointer type.

I disagree because it is impossible to mistake much from the documentation of the is expression:

https://dlang.org/spec/expression.html#is_expression

is(T == function)

means, is T a type, and is it a function type. Not a function pointer type.

What is a function type? It's the internal type that the compiler has for a function, which you actually cannot express in syntax.

Note from my example how both functions that need context and functions that do not need context both satisfy this test. Because they are all functions.

>

I stress strongly that there is not enough information there to take anything incorrectly. The reader has to construct a consistent mental model from that documentation. I did and my mental model is intact.

I did test with 'function' against 'delegate' and it worked as I still understand it. For the example I wrote, 'is' expression succeeds for 'function' but not for 'delegate' if the nested function makes use of local scope.

void main()
{
    int x;
    int iNeedContext() {
        return x;
    }
    static int iDontNeedContext() {
        return 5;
    }
    static assert(is(typeof(iNeedContext) == function));
    static assert(is(typeof(iDontNeedContext) == function));
    static assert(!is(typeof(&iNeedContext) == function));
    static assert(!is(typeof(&iDontNeedContext) == function));
}

I don't know how to show it any clearer. is(T == function) is testing whether T is a function type, not whether it needs context. It is always false for types that are not functions (including function pointers or delegates).

-Steve

4 days ago

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:

alias FT = void(int);

void v(int a){}
static assert(is(typeof(v) == function));
static assert(is(typeof(v) == FT));
3 days ago

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 to expression function types:

alias FT = void(int);

void v(int a){}
static assert(is(typeof(v) == function));
static assert(is(typeof(v) == FT));

Well, I was sure you couldn't do this! I thought the only way was to use typeof on an actual function.

But I stand corrected.

Looking at historical compilers, the alias ... = syntax was added in 2.087.0. But before then, you could also do it like:

alias void FT(int);

Which gives me so much C vibes...

-Steve

3 days ago

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. But before then, you could also do it like:

alias void FT(int);

Which gives me so much C vibes...

-Steve

You're right, I forgot that detail. The change in 2.087 was made exactly because there's was no equivalent for the alias = syntax.

1 2
Next ›   Last »