Thread overview
Exclamation symbol "!" within functions syntax
Jul 27, 2022
pascal111
Jul 27, 2022
Ali Çehreli
Jul 27, 2022
pascal111
Aug 01, 2022
pascal111
Aug 01, 2022
Paul Backus
Aug 01, 2022
pascal111
July 27, 2022

I noticed more than once that the exclamation "!" is used within functions typing, and it seems like an operator with new use, for example "to!int()", ".tee!(l => sum += l.length)", "enforce!MissingArguments...", so what dose it means?

July 27, 2022
On 7/27/22 04:00, pascal111 wrote:
> I noticed more than once that the exclamation "!" is used within functions typing, and it seems like an operator with new use, for example "to!int()", ".tee!(l => sum += l.length)", "enforce!MissingArguments...", so what dose it means?
> 

The binary ! operator is used for specifying template arguments. I have some explanation here:


http://ddili.org/ders/d.en/templates.html#ix_templates.!,%20template%20instance

Ali
July 27, 2022
On Wednesday, 27 July 2022 at 11:09:19 UTC, Ali Çehreli wrote:
> On 7/27/22 04:00, pascal111 wrote:
>> I noticed more than once that the exclamation "!" is used within functions typing, and it seems like an operator with new use, for example "to!int()", ".tee!(l => sum += l.length)", "enforce!MissingArguments...", so what dose it means?
>> 
>
> The binary ! operator is used for specifying template arguments. I have some explanation here:
>
>
> http://ddili.org/ders/d.en/templates.html#ix_templates.!,%20template%20instance
>
> Ali

I think I got it now, it's easy, I thought it so advanced D feature.
August 01, 2022
On Wednesday, 27 July 2022 at 11:09:19 UTC, Ali Çehreli wrote:
> On 7/27/22 04:00, pascal111 wrote:
>> I noticed more than once that the exclamation "!" is used within functions typing, and it seems like an operator with new use, for example "to!int()", ".tee!(l => sum += l.length)", "enforce!MissingArguments...", so what dose it means?
>> 
>
> The binary ! operator is used for specifying template arguments. I have some explanation here:
>
>
> http://ddili.org/ders/d.en/templates.html#ix_templates.!,%20template%20instance
>
> Ali

I noticed that filter is using the concept of templates but this time it's with a lambda function, not with a data type, how can we explain this? isn't supposed to use a data type after the exclamation mark: "auto r = chain(a, b).filter!(a => a > 0);"

https://dlang.org/phobos/std_algorithm_iteration.html#.filter.filter
August 01, 2022
On Monday, 1 August 2022 at 11:35:25 UTC, pascal111 wrote:
> I noticed that filter is using the concept of templates but this time it's with a lambda function, not with a data type, how can we explain this? isn't supposed to use a data type after the exclamation mark: "auto r = chain(a, b).filter!(a => a > 0);"
>
> https://dlang.org/phobos/std_algorithm_iteration.html#.filter.filter

If you look at the documentation for the filter template [1], you will notice that the "predicate" parameter is marked with the keyword "alias":

    template filter(alias predicate)

Alias template parameters are special. They can accept not only types, but also values, names of variables, and even things like modules and packages as arguments. You can read more about them in the "More Templates" chapter of Ali's book [2], and in the official D language specification [3].

[1] https://dlang.org/phobos/std_algorithm_iteration.html#.filter
[2] http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.alias,%20template%20parameter
[3] https://dlang.org/spec/template.html#aliasparameters
August 01, 2022
On Monday, 1 August 2022 at 12:58:27 UTC, Paul Backus wrote:
> On Monday, 1 August 2022 at 11:35:25 UTC, pascal111 wrote:
>> I noticed that filter is using the concept of templates but this time it's with a lambda function, not with a data type, how can we explain this? isn't supposed to use a data type after the exclamation mark: "auto r = chain(a, b).filter!(a => a > 0);"
>>
>> https://dlang.org/phobos/std_algorithm_iteration.html#.filter.filter
>
> If you look at the documentation for the filter template [1], you will notice that the "predicate" parameter is marked with the keyword "alias":
>
>     template filter(alias predicate)
>
> Alias template parameters are special. They can accept not only types, but also values, names of variables, and even things like modules and packages as arguments. You can read more about them in the "More Templates" chapter of Ali's book [2], and in the official D language specification [3].
>
> [1] https://dlang.org/phobos/std_algorithm_iteration.html#.filter
> [2] http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.alias,%20template%20parameter
> [3] https://dlang.org/spec/template.html#aliasparameters

Ok! I'll read about that from the suggested sources, but with respect to Ali's book, he should put "More Templates" after the chapter of "templates", but he put "Pragmas" instead of that http://ddili.org/ders/d.en/pragma.html