digitalmars.D.learn - Exclamation symbol "!" within functions syntax
- pascal111 (4/4) Jul 27 2022 I noticed more than once that the exclamation "!" is used within
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/11) Jul 27 2022 The binary ! operator is used for specifying template arguments. I have
- pascal111 (3/14) Jul 27 2022 I think I got it now, it's easy, I thought it so advanced D
- pascal111 (6/17) Aug 01 2022 I noticed that filter is using the concept of templates but this
- Paul Backus (14/20) Aug 01 2022 If you look at the documentation for the filter template [1], you
- pascal111 (5/27) Aug 01 2022 Ok! I'll read about that from the suggested sources, but with
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?
Jul 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
Jul 27 2022
On Wednesday, 27 July 2022 at 11:09:19 UTC, Ali Çehreli wrote:On 7/27/22 04:00, pascal111 wrote:I think I got it now, it's easy, I thought it so advanced D feature.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
Jul 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 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.filterI 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
Aug 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.filterIf 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
Aug 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: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.htmlI 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.filterIf 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
Aug 01 2022