December 24, 2010
On 12/23/10 6:11 PM, Caligo wrote:
> I hope I didn't miss anything; I copied it from the book.
[snip]

http://www.dsource.org/projects/phobos/changeset/2233

Don't forget to call your program stats.d or put a module stats declaration at its top.

Andrei
December 24, 2010
On 12/24/10, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> Don't forget to call your program stats.d or put a module stats declaration at its top.
>
> Andrei
>

Hardcoding module names in our code?! I beg to differ, sir!

module testmodule;

import std.string : split;
import std.stdio : writeln;

string modulename = split(.stringof)[1];

void main()
{
    writeln(modulename);
}
December 24, 2010
Thanks, Andrei. You're the best.

On Thu, Dec 23, 2010 at 9:14 PM, Andrei Alexandrescu < SeeWebsiteForEmail@erdani.org> wrote:

> On 12/23/10 6:11 PM, Caligo wrote:
>
>> I hope I didn't miss anything; I copied it from the book.
>>
> [snip]
>
> http://www.dsource.org/projects/phobos/changeset/2233
>
> Don't forget to call your program stats.d or put a module stats declaration at its top.
>
> Andrei
>


December 24, 2010
On 12/23/10 9:35 PM, Andrej Mitrovic wrote:
> module testmodule;
>
> import std.string : split;
> import std.stdio : writeln;
>
> string modulename = split(.stringof)[1];
>
> void main()
> {
>      writeln(modulename);
> }

What the... I didn't know you can do that. Thanks for the tip!

Andrei
December 24, 2010
I don't get it.  How is it able to get the name of the module like that?

On Thu, Dec 23, 2010 at 9:35 PM, Andrej Mitrovic <andrej.mitrovich@gmail.com
> wrote:

> On 12/24/10, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> > Don't forget to call your program stats.d or put a module stats declaration at its top.
> >
> > Andrei
> >
>
> Hardcoding module names in our code?! I beg to differ, sir!
>
> module testmodule;
>
> import std.string : split;
> import std.stdio : writeln;
>
> string modulename = split(.stringof)[1];
>
> void main()
> {
>    writeln(modulename);
> }
>


December 24, 2010
Am 23.12.2010 23:18, schrieb Andrei Alexandrescu:
>
> I wonder how stable D2 is when used as a "better D1", i.e. making
> conservative use of new features. I think the bread and butter support
> is as rock solid in both languages.

Depends on what parts of Phobos you use, I guess.
For example the streams and sockets are as suboptimal[1] as in D1/Phobos1, so one may prefer D1/Tango for that.

Cheers,
- Daniel

[1] See bugs #4234, #5177, #5001 and #5002 for example.
December 24, 2010
On Thu, 23 Dec 2010 23:18:06 -0600
Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:

> > module testmodule;
> >
> > import std.string : split;
> > import std.stdio : writeln;
> >
> > string modulename = split(.stringof)[1];
> >
> > void main()
> > {
> >      writeln(modulename);
> > }
> 
> What the... I didn't know you can do that. Thanks for the tip!

What is this syntactic form (".something")? Is there an explicit alternative, with a prefix?

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com

December 24, 2010
On 12/24/2010 07:18 AM, Andrei Alexandrescu wrote:
>
> What the... I didn't know you can do that. Thanks for the tip!
>
> Andrei

It's great we can do that. Though it doesn't make D's compile-time introspection much easier to work with. For example, look how we get overloads of a function in the current module:

void foo(int) {}
void foo(int, int) {}

template Alias(A...)
{
    alias A Alias;
}

template Overloads(alias parent, string name)
{
    alias Alias!(__traits(getOverloads, parent, name)) Overloads;
}

mixin("alias Overloads!(" ~ .stringof[7..$] ~ ", \"foo\") foos;");

For a simple use case like that, we have to exploit two hacks:

1. The Alias template is required since __traits cannot be used directly in the alias declaration. I believe this is a compiler bug.
2. We have to mixin the module identifier extracted from stringof instead of referencing the current module symbolically.

With the special 'meta' namespace Don proposed long ago, the above example could probably be as simple as:

alias meta.overloadsOf(meta.currentModule, "foo") foos;
December 24, 2010
> Yup. I use D almost exclusively in my professional work

Wow how did you do that?
People around here don't even know D exists.
December 24, 2010
Am 24.12.2010 10:41, schrieb spir:
> On Thu, 23 Dec 2010 23:18:06 -0600
> Andrei Alexandrescu<SeeWebsiteForEmail@erdani.org>  wrote:
>
>>> module testmodule;
>>>
>>> import std.string : split;
>>> import std.stdio : writeln;
>>>
>>> string modulename = split(.stringof)[1];
>>>
>>> void main()
>>> {
>>>       writeln(modulename);
>>> }
>>
>> What the... I didn't know you can do that. Thanks for the tip!
>
> What is this syntactic form (".something")? Is there an explicit alternative, with a prefix?
>
> Denis
> -- -- -- -- -- -- --
> vit esse estrany ☣
>
> spir.wikidot.com
>
A leading dot means looking up at the module's scope. An explicit prefix would be the module name but then you're back at hardcoding the modulename. And stringof is a special property of everything (I think) which gives you a compile-time string out of it.

Mafi