Jump to content
Excelsior Forums

Recommended Posts

Hello,

When I programing in modula2 sometimes I need to say FROM xxxx IMPORT ggg,gggg; but sometimes it is in of to say IMPORT xxx;

Why this different?

Greets Thanks a lot.

Share this post


Link to post
Share on other sites

They are two different ways of importing identifiers.

FROM xxx IMPORT ggg,gggg; 

    imports individual identifiers (procedures, types, sets, etc.);

IMPORT xxx; 

    imports everything in the module xxx.  You then need to qualify the identifier with the module name.

    You can use both methods in one program.  For example, say you want to use WriteString from TextIO and STextIO in the same program.

If you use

FROM STextIO IMPORT WriteString, WriteLn;
IMPORT TextIO;

You can then use the [tt]STextIO[/tt] version by calling [tt]WriteString,[/tt] and the [tt]TextIO[/tt] version by calling the qualified identifier [tt]TextIO.WriteString[/tt] (for writing to a file, for example).

You can qualify everything with

IMPORT STextIO, TextIO;

in which case you'd have to use: [tt]STextIO.WriteString[/tt] or [tt]TextIO.WriteString[/tt] every time.

Lots of people prefer using qualified identifiers all the time, as an aid in documenting their code, as it shows where a particular identifier comes from.

Note that you can use a combination with the same module, for example:

IMPORT Strings;
FROM Strings IMPORT FindNext, Extract;

Then, you could use [tt]FindNext[/tt] and [tt]Extract[/tt] directly, but if you wanted to use [tt]Concat,[/tt] you'd have to qualify it with [tt]Strings.Concat[/tt] (and if you forget what you've loaded, [tt]Strings.FindNext [/tt]and [tt]Strings.Extract[/tt] will also work, because you imported the whole module).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×