ada
#define ada: \
I------------------------------------------------------\
I------------------------------------------------------\
I------------------------------------------------------\
I \
I /$$$$$$ /$$ \
I /$$__ $$ | $$ \
I | $$ \ $$ /$$$$$$$ /$$$$$$ \
I | $$$$$$$$ /$$__ $$ |____ $$ \
I | $$__ $$| $$ | $$ /$$$$$$$ \
I | $$ | $$| $$ | $$ /$$__ $$ \
I | $$ | $$| $$$$$$$| $$$$$$$ \
I |__/ |__/ \_______/ \_______/ \
I------------------------------------------------------\
I------------------------------------------------------\
I------------------------------------------------------\
"In strong typing we trust." - Ada motto
• verbose
• safe-ish
• VERY strongly typed
• designed with garbage collection in mind,
however "An implementation need not support garbage collection ...",
due to historic speed concerns, dynamic memory is therefor usually manage by hand
• semicolonful
https://www.cs.uni.edu/~mccormic/4740/guide-c2ada.pdf
Files:
.ads : "ADa Specification"; decleration source file (~.h)
.adb : "ADa Body"; definition source file (~.c)
.ali : "Ada Library Information"; metadata file generated for a compialation unit
.o : object file
Programs:
gnat : GNU Ada compiler
gnat-make : GNU Ada build-system
Comments:
-- single line comment
Case:
• the language is case insensitive
Types:
• exceptionally strong typing system
Builtin:
Boolean:
type Boolean is (FALSE, TRUE);
Integer
Ordinary
Float
Decimal
Character
Strings:
• only String is an actual builtin, the rest belong to their respective
standard packages
|--------------|---------------------|--------------------------|-------------------------------|
| ############ | Character | Wide_Character | Wide_Wide_Character |
|--------------|---------------------|--------------------------|-------------------------------|
| Fixed | String | Fixed_Wide_String | Fixed_Wide_Wide_String |
| Bounded | Bounded_String | Bounded_Wide_String | Bounded_Wide_Wide_String |
| SuperBounded | SuperBounded_String | SuperBounded_Wide_String | SuperBounded_Wide_Wide_String |
| Unbounded | Unbounded_String | Unbounded_Wide_String | Unbounded_Wide_Wide_String |
|--------------|---------------------|--------------------------|-------------------------------|
Array
User:
Types:
• user types are treated as new types
• conversions will be required
type <name> is <type_specifier>;
<list> : enum; defines the set of valid values
mod <int> : modulus type; values have over- and underflows cycle
range <int-1> .. <int-2> : the valid value range is between <int-1> and <int-2>
delta <float> : the step between values is float
digits <int> : the number of valid digits is (+/-)<int>
record <elements> end record : struct
access <type> : pointer like
Subtypes:
• user subtypes "inherit" from an existing type
• conversion between and a type and a subtype is weak
subtype <name> is <typename>;
Type_qualifiers:
constant : makes a variable immutable
Definitions:
<name> : <type_qualifiers> <type> := <value>
Attributes:
• attributes are static values or const functions of a type
<type>'<attribute>
Enum:
• enum marks an enumeration value BELOW
<enum> Succ(<enum>) : value after <value>
<enum> Pred(<enum>) : value before <value>
<enum> Val(<int>) : <int>th value of the enumeration; reverse of 'Pos()
<int> Pos(<enum>) : position of <enum>; reverse of 'Val()
Range:
<int> First
<int> Last
<int> Length
<int> Range(<int>)
type My_Range is 0 .. 100;
My_Range'First -- 0
My_Range'Last -- 100
My_Range'Length -- 101
Modular:
<modular> Mod(<int>)
Casting:
<type>(<value>)
Operators:
+-----------------+-------+-----+
| Operator | C/C++ | Ada |
+-----------------+-------+-----+
| assignment | = | := |
| equality | == | = |
| non-equality | != | /= |
| plus equals | += | |
| subtract equals | -= | |
| multiply equals | *= | |
| division equals | /= | |
| or equals | |= | |
| and equals | &= | |
| modulus | % | mod |
| remainder | | rem |
| absolute value | | abs |
| exponentiation | | ** |
| range | | .. |
+-----------------+-------+-----+
Control:
Logic:
if <conidtion> then
-- ...
elsif <condition> then
-- ...
else
-- ...
end if;
case <value> is
when <value> => -- ...
when others => -- ...
end case;
loops:
{
(<limit>) loop
<...>
end loop;
}
<limit>
while <bool>
for <var> in <range>
Labels:
<name>: : creates a label named <name>
goto <name> : jumps to label named <name>
Exceptions:
raise <value>
exception
when <value> => -- ...
when others => -- ...
Subroutines:
{
<routine_type> <name> (return <typename>) is
<body>
}
<routine_type>
function : returns an Integer
procedure : does not return a value
<body>
{
<declarations>
begin
<...>
end <name>;
}
Operator_overloading:
{
function "<operator>"(<...>) is
<body>
}
Entry:
• the entry point of the program is considered the procedure named
after the file being compiled
Packages:
package <package-name> is
<delcarations>
end <package-name>
package body <package-name> is
<definitions>
end <package-name>
with <package-name> : import-s a package
use <package-name> : removes the need to refer to package contents as
<package-name>.<thing>; similar to C++ namespace using-s
Renaming:
<...-1> renames <...-2> : defines an alias
Generics:
pass
Tasks:
• language based multi-processing model
task <task-name> is
-- ...
end <task-name>
task body <task-name> is
-- ...
end <task-name>
Interfacing:
○ supported langauges:
• C/C++
• Cobol
• Fortran
Standard_packages:
Text_IO:
Put()
Put_Line()