How about adding NEW Special Tokens?? For ease and Security

Jose Armando Garcia jsancio at gmail.com
Wed May 25 15:05:37 PDT 2011


On Wed, May 25, 2011 at 1:20 PM, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 5/25/11 10:50 AM, Jose Armando Garcia wrote:
>>
>> On Wed, May 25, 2011 at 11:46 AM, KennyTM~<kennytm at gmail.com>  wrote:
>>>
>>> On May 25, 11 22:23, Matthew Ong wrote:
>>>>
>>>> On 5/25/2011 9:45 PM, Daniel Gibson wrote:
>>>>
>>>>
>>>>  >.stringof[7 .. $]
>>>> Belonging to which object or variable?
>>>
>>> Belongs to the module. '.xxx' is D's syntax for access a global object
>>> (derived from C++'s '::xxx' syntax). Please read through the whole D
>>> specification.
>>>
>>> (Frankly speaking this is a DMD-specific hack as the spec has never
>>> required
>>> that the .stringof of a module must return "module foo.bar.baz".)
>>>
>>
>> Is this evaluated at compile time? I prefer to use this for std.log
>> over __FILE__ when filtering verbose log messages. The user is more
>> likely to remember the module name and not the file name.
>
> It is. Probably it's a good idea to use module name, which is unique across
> an application, unlike the (directory-less) file name.
>

Actually, '.stringof' is not good enough for my use case. I would
really like __MODULE__! The nice thing about the __FILE__ and __LINE__
is that they are evaluated at the call site. It doesn't matter if you
use them in the value of template parameter or in the value of
function parameter. '.stringof' is getting evaluated in the module
where the function is declared so it is not really useful as a default
value. In other words I can't use it for std.log without polluting the
API.

Example:
---
$ cat test_module.d
module test_module;

import test_module2;

void func() { grabModuleName(); }

void main() { func(); }

$ cat  test_module2.d
module test_module2;

import std.stdio;

void grabModuleName(string moduleName = .stringof)()
{ writeln(moduleName); }

$ dmd test_module test_module2
$ ./test_module
module test_module2
---

-Jose

> Andrei
>


More information about the Digitalmars-d mailing list