RES: [fpc-pascal] dot within unit file name

John Stoneham captnjameskirk at gmail.com
Fri Jan 18 20:12:12 CET 2008


On 1/18/08, Vinzent Höfler <JeLlyFish.software at gmx.net> wrote:
> > On the other hand:
> >
> > uses a;
> >
> > var a:byte;
> >
> > ... both unit a as variable a would go into the global symtable, which
> > is the same lexical level, thus causing duplicate identifier conflicts.
>
> In Ada the fully qualified name of the variable would be "A.A" here.
>
> I certainly see the problems for the (Pascal) compiler write here, but
> from a user's point of view this identifier is in no way different than
> "SysUtils.Sleep".
>

Ada really does have an extremely well-defined and flexible
package/module system with the ability to define child packages, which
are conceptually identical to nestes packages/units. But there are
actually two keywords to handle modules and namespaces in Ada: "with"
and "use". When you "with" a module, you make it's identifiers
accessible to the current file, but only in a qualified manner: you
have to use dot notation for everything. So if you:
  with Unit_1;
you have to use:
  Unit_1.foo;
to access "foo" from "Unit_1". If you try to access "foo" without the
qualifier, you get compile errors because "foo" is unkown, only
"Unit_1.foo" is known.

However, you can also do:
  with Unit_1;  use Unit_1;
This imports the namespace of Unit_1 into the current file so that now
you *can* refernce "foo" without a qualifier. It's as if all the
identifiers in Unit_1 were defined in the current file (and so yes,
you can get conflicts).

To accomplish the same type module system that Ada has would require
at least another keyword (e.g. "with") in addition to "uses", and the
grammar would have to allow defining nested/child units.

But then Pascal would basically become Ada95.



More information about the fpc-pascal mailing list