"Hello D-world!", imports & South African D-naughts

Bosak bosak at gmail.com
Sat Aug 3 02:19:47 PDT 2013


On Saturday, 3 August 2013 at 09:02:32 UTC, Andre Artus wrote:
> On Saturday, 3 August 2013 at 06:51:40 UTC, evilrat wrote:
>> On Saturday, 3 August 2013 at 05:24:11 UTC, Andre Artus wrote:
>>> On Saturday, 3 August 2013 at 04:38:13 UTC, Andre Artus wrote:
>>>> Hello D-world!
>>>>
>>>> My name is Andre Artus, and I'm a programmer from 
>>>> Johannesburg, South Africa.
>>>>
>>>> I'm relatively new to D, but so far quite impressed by it. I 
>>>> have been reading Andrei Alexandrescu's "The D Programming 
>>>> Language" and Ali Çehreli's "Programming in D" to get up to 
>>>> speed. Both are quite good.
>>>>
>>>> 1st Q: Are there other S'frican D'philes on this forum?
>>>>
>>>> 2nd Q:
>>>>
>>>> I have noticed Andrei's use of the following construct with 
>>>> regard to static imports (p 346):
>>>>
>>>> static {
>>>> import teleport;
>>>> import time_travel, warp;
>>>> }
>>>>
>>>
>>> To answer my own question this seems to be an application of 
>>> the AttributeSpecifier rule. Which means that "public" and 
>>> "static" should probably be removed from the 
>>> ImportDeclaration rule.
>>
>> they shouldn't. static imports is handy that way to reduce 
>> namespace pollution(by forcing fully qualifying names), and 
>> public imports allow import other necessary modules just by 
>> importing one.
>
> I realize I was probably a bit unclear in my writing. I am not 
> advocating for the removal of these constructions of 'static' 
> or 'public' from the language. What I'm proposing is that this 
> specific area of the documentation does not accurately reflect 
> the grammar (or does so redundantly).
>
> What I tried to say is that the reference to 'static' and 
> 'public' in my implementation of ImportDeclaration (based on my 
> reading of the online docs) was redundant. I have since changed 
> my implementation and it now parses all the variants I 
> previously described including the following:
>
> static {
>   import teleport;
>   import time_travel, warp;
> }
>
> public {
>   import teleport;
>   import time_travel, warp;
> }
>
>
> The rule "static import ImportList ;" production given in 
> [ImportDeclaration](http://dlang.org/module.html#ImportDeclaration) 
> is redundant because it is already covered by 
> [AttributeSpecifier] 
> (http://dlang.org/attribute.html#AttributeSpecifier).
>
> ImportDeclaration:
> 	import ImportList ;
> 	**static import ImportList ; ** // seems redundant
>
>
> AttributeSpecifier:
>     Attribute :
>     Attribute DeclarationBlock
>
>
> Attribute:
>     // ...
>     ProtectionAttribute
>     **static**
>     // ...
>
> ProtectionAttribute:
>     private
>     package
>     protected
>     **public**
>     export

"The D Programming Language" is kind of old and out of date for 
the current version of D. There aren't many books for D so you 
have not much choice.
Attributes can be declared with 3 different syntaxes. For example 
one could write:
//--1--
/*Explicitly state attribute before every declaration*/
public int number;
public string name;
//--2--
/*State the attribute and then curly brackets and all the 
declarations inside have the attribute specified. Also note that 
those brackets don't introduce a new scope*/
public
{

}


More information about the Digitalmars-d-learn mailing list