Thread overview
Proposal for __LINE__, __FILE__ etc.
Mar 12, 2005
Daniel Kos
March 12, 2005
Is there any reason why these can't be pragmas?

writefln("This is line "~pragma(line));
writefln("Build 12345, built on "~pragma(timestamp));

Or is it just not.. a good idea to extend the language through pragmas?  I thought it might be a good idea as they don't have to be keywords, and at the same time, we don't have to implement a whole new language feature just to have them.  And they're prettier than __LINE__.


March 12, 2005
Jarrett Billingsley wrote:

> Is there any reason why these can't be pragmas?
> 
> writefln("This is line "~pragma(line));
> writefln("Build 12345, built on "~pragma(timestamp));

AFAIK, pragmas just affect other declaration/statements,
or have side effects outside the compilation such as
linking, and don't actually return anything themselves ?

http://www.digitalmars.com/d/pragma.html

> Or is it just not.. a good idea to extend the language through pragmas?  I thought it might be a good idea as they don't have to be keywords, and at the same time, we don't have to implement a whole new language feature just to have them.  And they're prettier than __LINE__. 

The current ones were not really meant to be pretty,
but have the same names as the ancient old C macros.
New language features, maybe get something prettier ?

Or not... (length = $)

--anders

PS: I don't think they're keywords,
    just predefined identifiers ?
March 12, 2005
> Is there any reason why these can't be pragmas?
>
> writefln("This is line "~pragma(line));
> writefln("Build 12345, built on "~pragma(timestamp));

I really like it!



-- 
uno (unodgs@tlen.pl)
March 13, 2005
> AFAIK, pragmas just affect other declaration/statements,
> or have side effects outside the compilation such as
> linking, and don't actually return anything themselves ?

That's the reason I wasn't sure if it was a good idea.  Then again, neither of the currently existing pragmas actually influence any expressions or statements ;)  And it also sort of makes sense to use the pragma expression, as pragma is used for compile-time statements, which is what __LINE__ etc. are.

> The current ones were not really meant to be pretty,
> but have the same names as the ancient old C macros.

They're only as ugly as they are now in order to.. somewhat dissuade people from using them, as they might not be kept in the language.  They still have a use, nonetheless, and a demand for them, so why not make them pretty like (most of) the rest of D?

> New language features, maybe get something prettier ?
> Or not... (length = $)

Haha :)

> PS: I don't think they're keywords,
>     just predefined identifiers ?

Either way, they're reserved.  Having predefined identifiers just seems .. kludgy to me.  Seems more solid if it's actually a construct in the language.