[fpc-pascal] Scoped enums and inferred types

Marco van de Voort marcov at stack.nl
Wed Feb 21 22:29:34 CET 2018


In our previous episode, Ryan Joseph said:
> > Having to decide a variable is scoped or not when it is declared is not the
> > most ideal solution anyway.  Logically you would decide that when creating
> > the scope, iow when importing, like in Modula2 or (afaik also) Extended
> > Pascal.
> 
> How does that look?

I don't know the EP syntax by heart, but M2 had

IMPORT X; 

and

FROM X IMPORT Y;
FROM X IMPORT QUALIFIED Y;

The first would import all identifiers of a module qualified (iow scoped),
so you could only access them as X.Y

The second one imports Y for use unqualified (so just "Y"), and the third,
as the keyword says, qualified again, but for a single identifier. The
places where Y is used in the FROM..IMPORt can be lists.

There was no unqualified mass-IMPORT (which would be like our USES).

IIRC FROM..IMPORTing an enum also imported all its fields, but I'm not
entirely sure, it has been 15+ years :-)

The system gave a lot of control, but as with all control that comes with a
lot of micromanaging and administration. While the purist probably won't
agree I missed an unqualified import (simples USES) dearly.

Still, it would be nice to have some similar control for special cases.

E.g. I can imagine very well that it would be nice to only import a handful of
procs and types from unit windows and avoid polution, and scoping all enums,
but descoping them with from import for special or heavy-usage cases.




More information about the fpc-pascal mailing list