Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Modula-3
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Modularity=== First and foremost, all compiled units are either <code>INTERFACE</code> or implementation <code>MODULE</code>s, of one flavor or another. An interface compiled unit, starting with the keyword <code>INTERFACE</code>, defines constants, types, variables, exceptions, and procedures. The implementation module, starting with the keyword <code>MODULE</code>, provides the code, and any further constants, types, or variables needed to implement the interface. By default, an implementation module will implement the interface of the same name, but a module may explicitly <code>EXPORT</code> to a module not of the same name. For example, the main program exports an implementation module for the Main interface. <syntaxhighlight lang="modula2"> MODULE HelloWorld EXPORTS Main; IMPORT IO; BEGIN IO.Put("Hello World\n") END HelloWorld. </syntaxhighlight> Any compiled unit may <code>IMPORT</code> other interfaces, although circular imports are forbidden. This may be resolved by doing the import from the implementation MODULE. The entities within the imported module may be imported, instead of only the module name, using the <code>FROM Module IMPORT Item [, Item]*</code> syntax: <syntaxhighlight lang="modula2"> MODULE HelloWorld EXPORTS Main; FROM IO IMPORT Put; BEGIN Put("Hello World\n") END HelloWorld. </syntaxhighlight> Typically, one only imports the interface, and uses the 'dot' notation to access the items within the interface (similar to accessing the fields within a record). A typical use is to define one [[data structure]] (record or object) per interface along with any support procedures. Here the main type will get the name 'T', and one uses as in <code>MyModule.T</code>. In the event of a name collision between an imported module and other entity within the module, the reserved word <code>AS</code> can be used as in <code>IMPORT CollidingModule AS X;</code>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)