digitalmars.D.learn - What does ! mean?
- Ky-Anh Huynh (16/16) Sep 27 2017 Hi,
- rikki cattermole (25/25) Sep 27 2017 There are two types of arguments in D. The runtime one (which you are
- Eugene Wissner (4/21) Sep 27 2017 See also the following chapter in Ali's book:
- Ky-Anh Huynh (3/5) Sep 27 2017 Thanks a lot. I will keep reading :)
- =?UTF-8?Q?Ali_=c3=87ehreli?= (13/18) Sep 27 2017 The fact that such an important operator is explained so late in the
- Mengu (3/11) Sep 27 2017 ustad, guess you can still write the new ed. :-)
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/4) Sep 27 2017 Since you're still around, one of these days... :)
- Arun Chandrasekaran (4/9) Sep 27 2017 This chapter is what hooked me with D. Naming that chapter as
- Gary Willoughby (3/6) Sep 27 2017 http://nomad.so/2013/07/templates-in-d-explained/
Hi, I am from Ruby world where I can have `!` (or `?`) in method names: `!` indicates that a method would modify its object (`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there is any official Ruby documentation on this convention though. ) In D I see `!` quite a lot. I have read the first 50 chapters in Ali's book but nowhere I see a note on `!`. It's about the compile thing, isn't it? E.g, ``` foo = formattedRead!"%s"(value); ``` But I also see `!` for some map/filter invocations. It's quite confusing me. Can you please explain and give any link where I can learn more about these things? Thanks a lot.
Sep 27 2017
There are two types of arguments in D. The runtime one (which you are well aware of) and the compile time one. A compile time argument is a constant passed in during construction of a symbol. But here is the thing, it isn't just limited to functions, you can have it on classes as well. --- class Foo(bool b) { bool get() { return b; } } void main() { Foo!true v = new Foo!true; assert(v.get); } --- Same logic going on. --- bool get(bool b)() { return b; } void main() { assert(get!true == true); } --- It can do more than a simple boolean being passed in, but that is the gist. Templates are wonderful (also read the spec!).
Sep 27 2017
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote:Hi, I am from Ruby world where I can have `!` (or `?`) in method names: `!` indicates that a method would modify its object (`foo.upcase!` means `foo = foo.upcase`). ( I don't know if there is any official Ruby documentation on this convention though. ) In D I see `!` quite a lot. I have read the first 50 chapters in Ali's book but nowhere I see a note on `!`. It's about the compile thing, isn't it? E.g, ``` foo = formattedRead!"%s"(value); ``` But I also see `!` for some map/filter invocations. It's quite confusing me. Can you please explain and give any link where I can learn more about these things? Thanks a lot.See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.html
Sep 27 2017
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote:See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.htmlThanks a lot. I will keep reading :)
Sep 27 2017
On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote:On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote:The fact that such an important operator is explained so late in the book is due to the book's strong desire to have a linear flow. Although binary ! appears before the templates chapter as to!int, format!"%s", etc., I decided to get to templates only after going through everything that could be templatized. (For example, even interfaces can be templates.) I don't claim this is the best choice but I'm happy that some people said that they found the linear flow useful. (I know that others would find it boring. :) ) If I were to write the book again, one other thing that I would explain earlier would be UFCS, and I would use much more of it in the examples. (UFCS was added to the language after I wrote most of the book.) AliSee also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.htmlThanks a lot. I will keep reading :)
Sep 27 2017
On Wednesday, 27 September 2017 at 17:58:27 UTC, Ali Çehreli wrote:On 09/27/2017 08:33 AM, Ky-Anh Huynh wrote:ustad, guess you can still write the new ed. :-)[...]Wissner wrote:[...]The fact that such an important operator is explained so late in the book is due to the book's strong desire to have a linear flow. [...]
Sep 27 2017
On 09/27/2017 03:06 PM, Mengu wrote:ustad, guess you can still write the new ed. :-)Since you're still around, one of these days... :) Ali
Sep 27 2017
On Wednesday, 27 September 2017 at 14:34:06 UTC, Eugene Wissner wrote:On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote:This chapter is what hooked me with D. Naming that chapter as "Templates for Human Beings" won't be an exaggeration.See also the following chapter in Ali's book: http://ddili.org/ders/d.en/templates.html
Sep 27 2017
On Wednesday, 27 September 2017 at 14:23:01 UTC, Ky-Anh Huynh wrote:Can you please explain and give any link where I can learn more about these things? Thanks a lot.http://nomad.so/2013/07/templates-in-d-explained/
Sep 27 2017