SlideShare a Scribd company logo
Modula-2
ISO/IEC 10514
programming language tutorial
Modules
Julian Miglio 2019
IMPLEMENTATION
The structure of a program
A complete Modula-2 program consists of a set of top-down interconnected modules in a dependency graph.
Modules are a powerful tool for creating large programs. They help make programs easier to modify by supporting information
hiding, help make programs more portable, make separate compilation possible,
and enable the development of libraries of reusable code.
Julian Miglio 2019
MODULE Main
DEFINITION
Main.mod
A.def
A.mod
IMPLEMENTATION
DEFINITION
C.def
C.mod
IMPLEMENTATION
DEFINITION
B.def
B.mod
The structure of a program
Modules are composed by two parts: the definition part and the implementation part that are contained in two files:
modulename.def (definition) , modulename.mod (implementation).
Modules act as walls. Entities declared inside a module are not visible outside the module unless they have been exported
by the module. A module may import from multiple other modules.
Julian Miglio 2019
MODULE MyProgram;
END MyProgram.
DEFINITION MODULE MyModule;
END MyModule.
IMPLEMENTATION MODULE MyModule;
END MyModule.
MyProgram.mod
MyModule.def
MyModule.mod
MyProgram uses entities exported by MyModule
IMPLEMENTATION MODULE MyModule;
BEGIN
END MyModule.
The structure of a module
DEFINITION MODULE MyModule;
END MyModule.
The definition part specifies the entities that the module exports, constitutes the externally visible interface of the module.
The implementation part contains the full implementation of all the entities.
The implementation part can have optionally a statemets part that is executed only once at the startup.
module name
MyModule.mod
MyModule.def
Julian Miglio 2019
end of module
statements for the startup part
An example of a module (definition)
DEFINITION MODULE Queue;
TYPE InroEntry = RECORD (* some fields *) END;
PROCEDURE Enter(info : InfoEntry; VAR ok: BOOLEAN);
PROCEDURE Remove(VAR info: InfoEntry; VAR ok: BOOLEAN);
END Queue.
In this example, the module Queue exports three entities: InfoEntry, Enter, Remove.
InfoEntry is a record type, in this example the fields are not defined for simplicity.
Enter and Remove are procedures.
Queue.def
Julian Miglio 2019
exported entities
An example of a module (implementation)
IMPLEMETATION MODULE Queue;
CONST buffleng = 128;
TYPE Bufferindex = [0 .. buffleng- 1];
VAR buffer : ARRAY Bufferindex OF InfoEntry;
enter, remove : Bufferindex;
PROCEDURE Enter(info : InfoEntry; VAR ok: BOOLEAN);
(* procedure implementation *)
END Enter.
PROCEDURE Remove(VAR info: InfoEntry; VAR ok: BOOLEAN);
(* procedure implementation *)
END Enter.
END Queue.
The exported procedures Enter and Remove are implemented in the implementation part of the module as well as
the other entities bufferlen, Bufferindex , enter and remove that are visible only inside on the module Queue.
In this example the procedures Enter and Remove are empty for simplicity.
Note that all the entities defined in the definition part are visible in the implementation part (e.g. InfoEntry).
Note that Modula-2 is case sensitive, Enter (procedure) is different than enter (variable).
Julian Miglio 2019
Queue.mod
Reference
Julian Miglio 2019
• Modula-2: Abstractions for Data and Programming Structures:
http://www.arjay.bc.ca/Modula-2/Text/index.html
• ISO/IEC 10514 Modula-2, Base Language: https://www.iso.org/standard/18583.html
• Modula2.org: https://www.modula2.org/

More Related Content

PDF
Modula-2 tutorial - 002b - module queue example
PDF
Modula 2 tutorial - 004 - visibility roles
PDF
Modula-2 tutorial - 001 - my fisrt program
PPTX
PPT
3.5 App structure.ppt
PPTX
user defined modules in python programing.pptx
PPTX
Linux Kernel Module - For NLKB
PDF
Unit-2 Introduction of Modules and Packages.pdf
Modula-2 tutorial - 002b - module queue example
Modula 2 tutorial - 004 - visibility roles
Modula-2 tutorial - 001 - my fisrt program
3.5 App structure.ppt
user defined modules in python programing.pptx
Linux Kernel Module - For NLKB
Unit-2 Introduction of Modules and Packages.pdf

Similar to Modula-2 tutorial - 002 - modules (20)

PDF
software design principles
PDF
C PROGRAMMING p-2.pdf
PDF
An Introductory course on Verilog HDL-Verilog hdl ppr
PPTX
10.-Modular-Programming-with function and Sub Procedure.pptx
PPTX
Angular modules in depth
PPTX
CSC2161Programming_in_Cpp_Lecture4-OOP Classes and Objects[1].pptx
PDF
Using Python Libraries.pdf
PPTX
Modules in Python Programming
PPTX
Managed extensibility framework
PPTX
Oosd lecture unit 4 ppt introduction part
PPT
module 3.4 Variables.ppt
PPTX
Modules and its usage in python for beginners
PPTX
Developer's Approach to Code Management
PDF
Linux kernel code
PDF
Unbundling the JavaScript module bundler - DublinJS July 2018
PPTX
Python Modules, executing modules as script.pptx
PPTX
Uninstall Hook in Odoo 17 - Odoo 17 Slides
PPTX
Python module 3, b.tech 5th semester ppt
PPTX
C++ Constructs.pptx
PDF
Verilog tutorial
software design principles
C PROGRAMMING p-2.pdf
An Introductory course on Verilog HDL-Verilog hdl ppr
10.-Modular-Programming-with function and Sub Procedure.pptx
Angular modules in depth
CSC2161Programming_in_Cpp_Lecture4-OOP Classes and Objects[1].pptx
Using Python Libraries.pdf
Modules in Python Programming
Managed extensibility framework
Oosd lecture unit 4 ppt introduction part
module 3.4 Variables.ppt
Modules and its usage in python for beginners
Developer's Approach to Code Management
Linux kernel code
Unbundling the JavaScript module bundler - DublinJS July 2018
Python Modules, executing modules as script.pptx
Uninstall Hook in Odoo 17 - Odoo 17 Slides
Python module 3, b.tech 5th semester ppt
C++ Constructs.pptx
Verilog tutorial
Ad

Recently uploaded (20)

PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
1_English_Language_Set_2.pdf probationary
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
advance database management system book.pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
History, Philosophy and sociology of education (1).pptx
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Empowerment Technology for Senior High School Guide
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Computing-Curriculum for Schools in Ghana
1_English_Language_Set_2.pdf probationary
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
advance database management system book.pdf
Orientation - ARALprogram of Deped to the Parents.pptx
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Weekly quiz Compilation Jan -July 25.pdf
Unit 4 Skeletal System.ppt.pptxopresentatiom
Digestion and Absorption of Carbohydrates, Proteina and Fats
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
History, Philosophy and sociology of education (1).pptx
Ad

Modula-2 tutorial - 002 - modules

  • 1. Modula-2 ISO/IEC 10514 programming language tutorial Modules Julian Miglio 2019
  • 2. IMPLEMENTATION The structure of a program A complete Modula-2 program consists of a set of top-down interconnected modules in a dependency graph. Modules are a powerful tool for creating large programs. They help make programs easier to modify by supporting information hiding, help make programs more portable, make separate compilation possible, and enable the development of libraries of reusable code. Julian Miglio 2019 MODULE Main DEFINITION Main.mod A.def A.mod IMPLEMENTATION DEFINITION C.def C.mod IMPLEMENTATION DEFINITION B.def B.mod
  • 3. The structure of a program Modules are composed by two parts: the definition part and the implementation part that are contained in two files: modulename.def (definition) , modulename.mod (implementation). Modules act as walls. Entities declared inside a module are not visible outside the module unless they have been exported by the module. A module may import from multiple other modules. Julian Miglio 2019 MODULE MyProgram; END MyProgram. DEFINITION MODULE MyModule; END MyModule. IMPLEMENTATION MODULE MyModule; END MyModule. MyProgram.mod MyModule.def MyModule.mod MyProgram uses entities exported by MyModule
  • 4. IMPLEMENTATION MODULE MyModule; BEGIN END MyModule. The structure of a module DEFINITION MODULE MyModule; END MyModule. The definition part specifies the entities that the module exports, constitutes the externally visible interface of the module. The implementation part contains the full implementation of all the entities. The implementation part can have optionally a statemets part that is executed only once at the startup. module name MyModule.mod MyModule.def Julian Miglio 2019 end of module statements for the startup part
  • 5. An example of a module (definition) DEFINITION MODULE Queue; TYPE InroEntry = RECORD (* some fields *) END; PROCEDURE Enter(info : InfoEntry; VAR ok: BOOLEAN); PROCEDURE Remove(VAR info: InfoEntry; VAR ok: BOOLEAN); END Queue. In this example, the module Queue exports three entities: InfoEntry, Enter, Remove. InfoEntry is a record type, in this example the fields are not defined for simplicity. Enter and Remove are procedures. Queue.def Julian Miglio 2019 exported entities
  • 6. An example of a module (implementation) IMPLEMETATION MODULE Queue; CONST buffleng = 128; TYPE Bufferindex = [0 .. buffleng- 1]; VAR buffer : ARRAY Bufferindex OF InfoEntry; enter, remove : Bufferindex; PROCEDURE Enter(info : InfoEntry; VAR ok: BOOLEAN); (* procedure implementation *) END Enter. PROCEDURE Remove(VAR info: InfoEntry; VAR ok: BOOLEAN); (* procedure implementation *) END Enter. END Queue. The exported procedures Enter and Remove are implemented in the implementation part of the module as well as the other entities bufferlen, Bufferindex , enter and remove that are visible only inside on the module Queue. In this example the procedures Enter and Remove are empty for simplicity. Note that all the entities defined in the definition part are visible in the implementation part (e.g. InfoEntry). Note that Modula-2 is case sensitive, Enter (procedure) is different than enter (variable). Julian Miglio 2019 Queue.mod
  • 7. Reference Julian Miglio 2019 • Modula-2: Abstractions for Data and Programming Structures: http://www.arjay.bc.ca/Modula-2/Text/index.html • ISO/IEC 10514 Modula-2, Base Language: https://www.iso.org/standard/18583.html • Modula2.org: https://www.modula2.org/