Import concerns revisited

Derek Parnell derek at nomail.afraid.org
Sun Jul 9 17:55:18 PDT 2006


On Sun, 09 Jul 2006 16:57:55 -0700, kris wrote:

> Dave wrote:
>> Actually, how about:
>> 
>> import from some.long.modid func as f1, abcd, efgh as zzz;
>> private import from this.other.cool.db.lib as dblib;
>> 
>> Is more consistent w/ current syntax, maintains the visual continuity, 
>> allows more than one symbol import per module (w/o retyping the module), 
>> and combines the import w/ the alias if desired.
>> 
>> - Dave
> 
> Don't wish to belabour the point, but why the private attribute when 
> it's not really required?

Because a 'private' import is supposed to prevent modules that import the
one with the private import from seeing the members of that privately
imported module. Otherwise it could reference those members *as if* it had
also imported it.

The examples below ignore the current bug in DMD about FQN overriding
privacy.

 -- aaa.d --
 int X;

 -- bbb.d --
 private import aaa;
 void func_bbb()
 {
  aaa.X = 1;
 }

 -- ccc.d ---
 import bbb;
 void func_ccc()
 {
  aaa.X = 5; // Illegal 'cos bbb imported aaa privately.
 }


However ...

 -- bbb.d --
 import aaa;
 void func_bbb()
 {
  aaa.X = 1;
 }

 -- ccc.d ---
 import bbb;
 void func_ccc()
 {
  aaa.X = 5; // Okay now.
 }


-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
10/07/2006 10:45:15 AM



More information about the Digitalmars-d mailing list