- Published on
COMP2310 - Week 1 - Ada fundamentals
Table of Contents
Notes
Header files -> Used to define program specifications or compilation units are stored in .ads files
Implementation files -> Contain the executable code in .adb files which contain the implementation.
Note that the .ads files can be created first and used to check program types and syntax before it is actually implemented within the .adb files.
The with keyword is similar to the include in C/C++ or import in Python and Java.
The package name itself can be ommited by using the use keyword. Similar to the using <namespace> in C/C++ or import in Java.
with Ada.Text_IO;
procedure Greet is begin Ada.Text_IO.Put_Line ("Hello, World!");end Greet;with Ada.Text_IO; use Ada.Text_IO;
procedure Greet is begin Put_Line ("Hello, World!");end Greet;Package
Java packages is used as a namespace for classes. In Ada it is often a compilation unit.
package Name is -- public declarations private -- private declarationsend Name;package body Name is -- implementation end Name;private -> Allows for use available for use while hiding the actual implementation.
record -> Ada's C/C++ struct whose fields are only visible to its package and not to the caller.
- Caller can refer to objects of that type, but not change the contents directly.
Introduction
with Ada.Text_IO;
procedure Greet is begin Ada.Text_IO.Put_Line ("Hello, World!");end Greet;procedure -> Similar to a void function in C/C++ or Java.