Thread overview
what wrong with this alias
Jan 08, 2023
Qusatlegadus
Jan 08, 2023
Salih Dincer
Jan 08, 2023
Salih Dincer
January 08, 2023
auto s = 1234.to!string.map!q{a - '0'}.sum;

works fine.

but if i do an alias

alias comb = to!string.map!q{a - '0'}

Error: unknown, please file report on issues.dlang.org

What's wrong with this alias?

January 08, 2023

On Sunday, 8 January 2023 at 05:42:46 UTC, Qusatlegadus wrote:

>

What's wrong with this alias?

import std;
alias comb = map!q{a - '0'};
void main()
{
    auto s = 2234.to!string.map!q{a - '0'}.sum;
    s.to!string.comb.sum.writeln;
    // thiS works: "2"
}

SDB@79

January 08, 2023

On Sunday, 8 January 2023 at 05:42:46 UTC, Qusatlegadus wrote:

>
auto s = 1234.to!string.map!q{a - '0'}.sum;

works fine.

but if i do an alias

alias comb = to!string.map!q{a - '0'}

Error: unknown, please file report on issues.dlang.org

What's wrong with this

Simple explanation

to!string is a function expecting 1 argument, which you're not providing in your alias. Convert your alias to a lambda expression:

alias comb = x => x.to!string.map!q{a - '0'}

Complicated explanation

to is a template defined like this:

// https://github.com/dlang/phobos/blob/master/std/conv.d
template to(T)
{
    T to(A...)(A args)
        if (A.length > 0)
    {
        return toImpl!T(args);
    }
    // some overloads omitted for brevity
}

to needs at least 2 template arguments - the first one for the outer template is passed explicitly (what you did with to!string), the other ones are inferred from the arguments passed to the to function. Since you did not pass an argument to to!string, the inner template doesn't get instantiated.

Basically what happens is you're trying to pass an uninstantiated template as argument to map. This is quite an exotic situation, so probably there isn't a dedicated error message for it or you're hitting a bug in the compiler (hence the unknown error message).

January 08, 2023

On Sunday, 8 January 2023 at 09:45:09 UTC, Krzysztof Jajeśnica wrote:

>

Simple explanation

to!string is a function expecting 1 argument, which you're not providing in your alias. Convert your alias to a lambda expression:

alias comb = x => x.to!string.map!q{a - '0'}

A logical solution...

Since your goal is to manipulate numbers, it is possible to convert directly to char type:

import std.algorithm : map, sum;
import std.conv : toChars;

alias comb = (uint x) => x.toChars.map!"a - '0'";
void main()
{
    auto s = 2234.comb.sum;
    assert(s.comb.sum == 2);
}

SDB@79

January 09, 2023

On 1/8/23 12:42 AM, Qusatlegadus wrote:

>

    auto s = 1234.to!string.map!q{a - '0'}.sum;
works fine.

but if i do an alias

    alias comb = to!string.map!q{a - '0'}

    Error: unknown, please file report on issues.dlang.org

What's wrong with this alias?

Aside from the problem with the code, that error alone deserves a bug report so...

https://issues.dlang.org/show_bug.cgi?id=23615

-Steve