www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Meaning of the dot-function syntax

reply dhs <dhs email.com> writes:
Hi,

What's the meaning of the dot in the call to writeln() below?

```d
     .writeln("Hello there!");
```

I haven't found this in the spec or anywhere else. This is used 
very often in the source code for Phobos.

Thanks,
dhs
Oct 01 2023
next sibling parent reply Anonymouse <zorael gmail.com> writes:
On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote:
 Hi,

 What's the meaning of the dot in the call to writeln() below?

 ```d
     .writeln("Hello there!");
 ```

 I haven't found this in the spec or anywhere else. This is used 
 very often in the source code for Phobos.

 Thanks,
 dhs
Quote https://dlang.org/spec/module.html#module_scope_operators;
 A leading dot (`.`) causes the identifier to be looked up in 
 the module scope.
 
 ```d
 int x;

 int foo(int x)
 {
     if (y)
         return x;  // returns foo.x, not global x
     else
         return .x; // returns global x
 }
 ```
Oct 01 2023
parent dhs <dhs email.com> writes:
On Sunday, 1 October 2023 at 09:20:32 UTC, Anonymouse wrote:
 On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote:
 Hi,

 What's the meaning of the dot in the call to writeln() below?

 ```d
     .writeln("Hello there!");
 ```

 I haven't found this in the spec or anywhere else. This is 
 used very often in the source code for Phobos.

 Thanks,
 dhs
Quote https://dlang.org/spec/module.html#module_scope_operators;
 A leading dot (`.`) causes the identifier to be looked up in 
 the module scope.
 
 ```d
 int x;

 int foo(int x)
 {
     if (y)
         return x;  // returns foo.x, not global x
     else
         return .x; // returns global x
 }
 ```
Oh thank you, especially the link to the spec!
Oct 01 2023
prev sibling parent reply evilrat <evilrat666 gmail.com> writes:
On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote:
 Hi,

 What's the meaning of the dot in the call to writeln() below?

 ```d
     .writeln("Hello there!");
 ```

 I haven't found this in the spec or anywhere else. This is used 
 very often in the source code for Phobos.

 Thanks,
 dhs
It is either means "use global scope writeln" in cases when there is local writeln in the scope shadowing global one, or simply a chained calls like myarray.filter().sort().map() each on new line.
Oct 01 2023
parent dhs <dhs email.com> writes:
On Sunday, 1 October 2023 at 09:24:39 UTC, evilrat wrote:
 On Sunday, 1 October 2023 at 08:22:48 UTC, dhs wrote:
 Hi,

 What's the meaning of the dot in the call to writeln() below?

 ```d
     .writeln("Hello there!");
 ```

 I haven't found this in the spec or anywhere else. This is 
 used very often in the source code for Phobos.

 Thanks,
 dhs
It is either means "use global scope writeln" in cases when there is local writeln in the scope shadowing global one, or simply a chained calls like myarray.filter().sort().map() each on new line.
Thanks.
Oct 01 2023