[fpc-devel] Re: [fpc-pascal] Re: Ideas for namespace implementation

Martin fpc at mfriebe.de
Mon Jul 26 17:18:34 CEST 2010


On 26/07/2010 15:55, Sven Barth wrote:
> Hi!
>
> So... continuing the thread were it belongs... in fpc-devel :P
>
> On 26.07.2010 16:36, Marcos Douglas wrote:
>> On Mon, Jul 26, 2010 at 11:20 AM, Sven Barth
>> <pascaldragon at googlemail.com>  wrote:
>>>
>>> What about that the compiler enforces that you use the fully
>>> qualified name
>>> if you used it in the uses?
>>
>> Not only if you used it in the uses clause, but if you COMPILED with
>> namespace sintaxe (eg. by Graeme unit strutils namespace my), IMHO...
>
> The whole idea is to compile units with a namespace not just using on
> in the uses because it's funny.
> Either its compiled by including "namespace Foo" in the units
> themselves or by using a commandline parameter "-namespace Foo", so
> that not every unit needs so be changed (both modes are supported and
> the "in unit" version takes precedence of the commandline one).
>
>> But we would have a problem stated by Michael:
>>
>> On Mon, Jul 26, 2010 at 6:34 AM, Michael Van Canneyt
>> <michael at freepascal.org>  wrote:
>>> Well, I fail to see what is more logical in my.constants than in
>>> myconstants.
>>> The unit is still called my.constants, not constants. So you'll end up
>>> typing my.constants everywhere anyway. The gain of this over
>>> myconstants is
>>> highly debatable.
>
> It's not about not having to type the "fully qualified name", but
> about not having to rename/prefix my own units, because they conflict
> with an existing unit.

Ok, so that means:
If refering to the unit, or any element in it, you always have to use 
the full namespace:
uses my.utils;
var a: my.utils.TFoo;

that is, inside the unit that uses the other unit, the other units name 
is effectively "my.utils" => with the dot being part of the name

If writing a unit, that is to be in a namespace you can do
   unit utils namespace my;
but that is no different from doing
   unit my.utils;

*** up to this point, there is no difference to using a prefix on the 
unit name? "unit MyUtils" ***

The new thing is that you are allowed to give the namespace on the 
commandline, effectively allowing to change it without needing to change 
all of the sources

But that can be done for prefixes too:
   fpc -unitprefix=My Utils.pas

It acts like a pre-processor, it will find the unit declaration, and 
prefix the unit name...

So no fancy-new and introducing-problems (ambiguity mu.utils.a => unit 
my; record utils) issue....

--------------
In fact if the existing
uses Foo in 'dir';

could be extended to allow a package or similar
uses Foo in 'LCL'

and an alias directive would be introduced, then it was all solved too

uses Foo in 'lcl' alias 'FooLCL', Foo in 'RTL' alias 'FooRTL'








More information about the fpc-devel mailing list