### Illustrating Get Procedure Input Behavior and Data_Error (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-A-10-6.html This commented example demonstrates various input scenarios for the `Get` procedure, showing how different character sequences are parsed into an integer `N`. It also illustrates a case where `Data_Error` is raised due to an invalid character terminating the numeric literal. ```Ada -- Characters at input Sequence input Value of N -- bb–12535b –12535 –12535 -- bb12_535e1b 12_535e1 125350 -- bb12_535e; 12_535e (none) Data_Error raised ``` -------------------------------- ### Declaring the Ada.Text_IO Package with IO Exceptions Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-3-2-4.html This snippet shows the beginning of the `Ada.Text_IO` package declaration, indicating its dependency on `Ada.IO_Exceptions`. This setup allows the `Text_IO` package to define and handle specific I/O related exceptions, crucial for robust file operations. ```Ada with Ada.IO_Exceptions; package Ada.Text_IO is ``` -------------------------------- ### Reading Integer Input with Get Procedure (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-A-10-6.html This snippet declares an integer variable `N` and then uses the `Get` procedure to read an integer value from the input stream into `N`. The `Get` procedure handles parsing of numeric literals, skipping leading blanks. ```Ada N : Integer; ... Get(N); ``` -------------------------------- ### Implementing Buffer Protected Object Body - Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-9-11.html Starts the implementation of the 'Buffer' protected object's body, which contains the logic for its entries, procedures, and functions. This section will define the behavior of the buffer's operations. ```Ada protected body Buffer is ``` -------------------------------- ### Illustrating Get Procedure Behavior and Data_Error in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-10-6.html This section provides examples of how the Get procedure processes different input sequences for an integer type. It shows successful parsing, handling of underscores in numeric literals, and an instance where Data_Error is raised due to an invalid character terminating the numeric literal. ```Ada -- Characters at input Sequence input Value of N -- bb–12535b –12535 –12535 -- bb12_535e1b 12_535e1 125350 -- bb12_535e; 12_535e (none) Data_Error raised ``` -------------------------------- ### Instantiating and Using Float_IO for Real Type in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-A-10-9.html This example instantiates the `Float_IO` generic package with the `Real` type, creating `Real_IO`. The `use Real_IO;` clause makes the procedures and types declared within `Real_IO` directly visible, simplifying calls to `Put` and `Get` for `Real` numbers. ```Ada package Real_IO is new Float_IO(Real); use Real_IO; ``` -------------------------------- ### Declaring Public Child Package Rational_Numbers.IO (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-10-1-1.html This snippet declares a public child package Rational_Numbers.IO for handling input/output operations related to Rational numbers. It specifies Put and Get procedures for writing and reading Rational values. This package is a child of Rational_Numbers. ```Ada package Rational_Numbers.IO is -- public child of Rational_Numbers, see [7.1] procedure Put(R : in Rational); procedure Get(R : out Rational); end Rational_Numbers.IO; ``` -------------------------------- ### Illustrating Ada Pragma Usage Examples Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-2-8.html This snippet provides concrete examples of how to apply various pragmas in Ada code. It demonstrates disabling compilation listings, turning off optional optimizations, enforcing assertion checks, and performing a conditional assertion with a custom error message. These examples showcase common use cases for controlling compiler behavior and ensuring code correctness. ```Ada pragma List(Off); -- _turn off listing generation_ ``` ```Ada pragma Optimize(Off); -- _turn off optional optimizations_ ``` ```Ada pragma Assertion_Policy(Check); -- _check assertions_ ``` ```Ada pragma Assert(Exists(File_Name), Message => "Nonexistent file"); -- _assert file exists_ ``` -------------------------------- ### Example Main Procedure Using Rational_Numbers.IO (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-10-1-1.html This Main procedure serves as a root library program demonstrating the usage of Rational_Numbers.IO and Ada.Text_IO. It declares a Rational variable, assigns a value, and then uses the Put procedures from both Ada.Text_IO and Rational_Numbers.IO to display output to the console. It showcases how to construct and print a rational number. ```Ada with Rational_Numbers.IO; use Rational_Numbers; with Ada.Text_io; -- see [A.10] procedure Main is -- a root library procedure R : Rational; begin R := 5/3; -- construct a rational number, see [7.1] Ada.Text_IO.Put("The answer is: "); IO.Put(R); Ada.Text_IO.New_Line; end Main; ``` -------------------------------- ### Main Procedure Demonstrating Rational Numbers IO in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-10-1-1.html This `Main` procedure demonstrates the usage of the `Rational_Numbers.IO` package. It uses a `with` clause to import the I/O package and a `use` clause for convenience, then constructs a rational number, prints a message, outputs the rational number, and adds a new line. ```Ada with Rational_Numbers.IO; use Rational_Numbers; with Ada.Text_io; -- see [A.10](AA-A-10.html) procedure Main is -- a root library procedure R : Rational; begin R := 5/3; -- construct a rational number, see [7.1](AA-7-1.html) Ada.Text_IO.Put("The answer is: "); IO.Put(R); Ada.Text_IO.New_Line; end Main; ``` -------------------------------- ### Main Program Demonstrating Library Unit Usage in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-10-1-1.html This is a main procedure `Main` that serves as a root library unit. It demonstrates the usage of the `Rational_Numbers.IO` package (aliased via `use Rational_Numbers;` for direct `IO.Put` calls) and the standard `Ada.Text_IO` package. It initializes a `Rational` number, prints a message, and then prints the rational number using the custom `IO.Put`. ```Ada with Rational_Numbers.IO; use Rational_Numbers; with Ada.Text_io; procedure Main is R : Rational; begin R := 5/3; Ada.Text_IO.Put("The answer is: "); IO.Put(R); Ada.Text_IO.New_Line; end Main; ``` -------------------------------- ### Declaring the Get Procedure for Character Input in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-3-2-4.html This snippet declares the `Get` procedure, which reads a single character from an `Input_File_Type`. It ensures that the file is open and in input mode before attempting to read, leveraging the predicates defined on `Input_File_Type` for robust input operations. ```Ada procedure Get (File : in Input_File_Type; Item : out Character); ``` -------------------------------- ### File Creation and Opening Procedures in Ada.Sequential_IO Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-8-1.html These procedures handle the creation and opening of sequential files. `Create` initializes a new file, optionally specifying mode, name, and form. `Open` associates an existing file with a `File_Type` object, requiring a mode and name. ```Ada procedure Create(File : in out File_Type; Mode : in File_Mode := Out_File; Name : in String := ""; Form : in String := ""); procedure Open (File : in out File_Type; Mode : in File_Mode; Name : in String; Form : in String := ""); ``` -------------------------------- ### Examples of Integer_IO.Put Calls in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-10-8.html These examples demonstrate various uses of the `Put` procedure from the `Int_IO` package (an instantiation of `Text_IO.Integer_IO`). They show how to output integer values with default formatting, specified width, and different bases (e.g., binary). The comments indicate the expected output string for each call. ```Ada Put(126); -- "b126" Put(-126, 7); -- "bbb–126" Put(126, Width => 13, Base => 2); -- "bbb2#1111110#" ``` -------------------------------- ### Reading Integer Input with Get in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-10-6.html This snippet declares an integer variable `N` and then uses the `Get` procedure to read an integer value from the input stream into `N`. The examples illustrate how `Get` handles different input formats, where 'b' represents a space: `bb-12535b` results in `N` being `-12535`; `bb12_535e1b` results in `N` being `125350`; and `bb12_535e;` raises a `Data_Error` because the input sequence is not a valid numeric literal. ```Ada N : Integer; ... Get(N); ``` -------------------------------- ### Demonstrating Pragma Usage in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-2-8.html This snippet provides practical examples of different Ada pragmas, including `List`, `Optimize`, `Pure`, and `Assert`. It shows how these pragmas are invoked with specific arguments to control compiler behavior, optimize code, categorize packages, or assert conditions at compile time. ```Ada pragma List(Off); -- turn off listing generation pragma Optimize(Off); -- turn off optional optimizations pragma Pure(Rational_Numbers); -- set categorization for package pragma Assert(Exists(File_Name), Message => "Nonexistent file"); -- assert file exists ``` -------------------------------- ### Declaring the Get Procedure for Character Input in Ada.Text_IO Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-3-2-4.html This Ada code declares the `Get` procedure in `Ada.Text_IO` for reading a single character from a file. It takes an `Input_File_Type` parameter, ensuring the file is open and in input mode, and an `out Character` parameter to store the read character. This procedure is fundamental for character-by-character input operations. ```Ada procedure Get (File : in Input_File_Type; Item : out Character); ``` -------------------------------- ### Example of Float_IO Package Instantiation and Usage (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-10-9.html This example shows how to instantiate `Text_IO.Float_IO` for a custom `Real` type, then declare a `Real` variable and use the `Put` procedure with various formatting options. It illustrates default formatting, named parameter usage, and positional parameter usage for controlling output precision and exponent display. ```Ada package Real_IO is new Float_IO(Real); use Real_IO; X : Real := -123.4567; -- digits 8 Put(X); -- default format -- "–1.2345670E+02" Put(X, Fore => 5, Aft => 3, Exp => 2); -- "bbb–1.235E+2" Put(X, 5, 3, 0); -- "b–123.457" ``` -------------------------------- ### Protected Subprogram Calls in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-9-5-1.html These examples demonstrate various protected subprogram calls in Ada, including setting and getting components of a shared array and releasing control. These operations are performed on protected objects to ensure safe concurrent access in a multi-tasking environment, as detailed in section 9.4 of the reference manual. ```Ada Shared_Array.Set_Component(N, E); ``` ```Ada E := Shared_Array.Component(M); ``` ```Ada Control.Release; ``` -------------------------------- ### Calling Procedures of Instantiated Generic Packages in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-12-8.html This snippet shows how to invoke the `Push` procedure on the previously instantiated `Stack_Int` and `Stack_Bool` packages. It demonstrates the direct use of the package-qualified procedures for adding elements to the respective stacks. ```Ada Stack_Int.Push(N); Stack_Bool.Push(True); ``` -------------------------------- ### Getting Root Node Cursor in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-10.html This function returns a Cursor that designates the root node of the specified Tree Container. This cursor can then be used to navigate or query the tree starting from its root. ```Ada function Root (Container : Tree) return Cursor; ``` -------------------------------- ### Accessing Base Minimum Value of Enumeration Type in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-4-1-4.html This example shows how to get the minimum value of the base type of an enumeration, which is equivalent to 'Color'First. It uses the 'Base'First attributes on the 'Rainbow' type. ```Ada Rainbow'Base'First ``` -------------------------------- ### Demonstrating Integer Output with Put Procedure in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-10-8.html This snippet demonstrates various uses of the `Put` procedure from the `Int_IO` package to output integer values. It shows default output, output with a specified width, and output with a specified width and base (binary representation). The comments illustrate the resulting string output for each call. ```Ada Put(126); -- "b126" Put(-126, 7); -- "bbb–126" Put(126, Width => 13, Base => 2); -- "bbb2#1111110#" ``` -------------------------------- ### Calling Procedures of Instantiated Stack Packages in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-12-8.html This Ada code illustrates how to call the `Push` procedure on instances of the generic `Stack` package. It shows pushing an integer `N` onto `Stack_Int` and a boolean `True` onto `Stack_Bool`, demonstrating the use of the instantiated packages. ```Ada Stack_Int.Push(N); Stack_Bool.Push(True); ``` -------------------------------- ### Demonstrating Generalized Indexing Calls in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-4-1-6.html This example declares an instance of `Indexed_Barrel` and illustrates various equivalent ways to perform generalized indexing. It shows traditional function calls, prefixed views, and implicit indexing/dereferencing, highlighting the flexibility of Ada's generalized indexing. ```Ada IB: aliased Indexed_Barrel; -- All of the following calls are then equivalent: Find (IB,"pear").Data.all := Element'(...); -- Traditional call IB.Find ("pear").Data.all := Element'(...); -- Call of prefixed view IB.Find ("pear") := Element'(...); -- Implicit dereference (see [4.1.5]) IB ("pear") := Element'(...); -- Implicit indexing and dereference IB ("pear").Data.all := Element'(...); -- Implicit indexing only ``` -------------------------------- ### Defining and Using Comments in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-2-7.html These examples demonstrate the various ways comments can be used in Ada. Comments begin with two hyphens and extend to the end of the line. Multi-line comments are achieved by starting each line with the comment delimiter. ```Ada -- the last sentence above echoes the Algol 68 report ``` ```Ada end; -- processing of Line is complete ``` ```Ada -- a long comment may be split onto -- two or more consecutive lines ``` ```Ada ---------------- -- the first two hyphens start the comment ``` -------------------------------- ### Getting Last Element Cursor in Ada Set Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-9.html This function returns a `Cursor` pointing to the last element in the `Container` set. The cursor can be used for iteration or accessing the element at that position. It's useful for starting a reverse traversal. ```Ada function Last (Container : Set) return Cursor; ``` -------------------------------- ### Demonstrating Ada Generalized Indexing Calls Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-4-1-6.html This Ada code block illustrates several equivalent ways to perform generalized indexing on the `IB` object. It shows the traditional function call, a prefixed view call, implicit dereferencing, and implicit indexing with and without explicit data access, highlighting the flexibility of Ada's generalized indexing feature. ```Ada Find (IB,"pear").Data.all := Element'(...); -- _Traditional call_ IB.Find ("pear").Data.all := Element'(...); -- _Call of prefixed view_ IB.Find ("pear") := Element'(...); -- _Implicit dereference (see [4.1.5](AA-4-1-5.html))_ IB ("pear") := Element'(...); -- _Implicit indexing and dereference_ IB ("pear").Data.all := Element'(...); -- _Implicit indexing only_ ``` -------------------------------- ### Getting First Element Cursor in Ada Set Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-9.html This function returns a `Cursor` pointing to the first element in the `Container` set. The cursor can then be used for iteration or accessing the element at that position. It's useful for starting a forward traversal. ```Ada function First (Container : Set) return Cursor; ``` -------------------------------- ### Demonstrating Entry Calls in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-9-5-3.html This snippet provides several examples of how entry calls are made in Ada. These calls are used to interact with tasks or protected objects, initiating a rendezvous or a protected action. Each example illustrates a different syntax or context for an entry call, such as simple calls, calls with parameters, or indexed entry calls. ```Ada Agent.Shut_Down; Parser.Next_Lexeme(E); Pool(5).Read(Next_Char); Controller.Request(Low)(Some_Item); Flags(3).Seize; ``` -------------------------------- ### Insert Default Elements by Cursor and Get Position - Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-2.html This procedure inserts a specified number of default-initialized elements into the Container Vector before the given Cursor. It also returns a Cursor to the start of the newly inserted elements. ```Ada procedure Insert (Container : in out Vector; Before : in Cursor; Position : out Cursor; Count : in Count_Type := 1); ``` -------------------------------- ### Instantiating a Generic Stack Package in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-12-8.html This snippet demonstrates how to create concrete instances of the generic `Stack` package. It instantiates `Stack_Int` for integers with a size of 200 and `Stack_Bool` for booleans with a size of 100, making the generic functionality available for specific types and sizes. ```Ada package Stack_Int is new Stack(Size => 200, Item => Integer); package Stack_Bool is new Stack(100, Boolean); ``` -------------------------------- ### Insert Uninitialized Space by Cursor and Get Position - Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-2.html This procedure inserts a specified number of uninitialized elements (raw space) into the Container Vector before the given Cursor. It returns a Cursor to the start of the newly inserted space. ```Ada procedure Insert_Space (Container : in out Vector; Before : in Cursor; Position : out Cursor; ``` -------------------------------- ### Creating a Fixed-Size Slice in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-4-1-2.html This example demonstrates creating a slice of 15 characters from an array named 'Stars', starting from index 1 and ending at index 15. This forms a new one-dimensional array representing that specific range. ```Ada Stars(1 .. 15) ``` -------------------------------- ### Instantiating Ada Generic Packages and Containers Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-12-7.html This example demonstrates the instantiation of the 'Ordered_Join' generic package, along with 'Ada.Containers.Ordered_Maps', within a 'Symbol_Package'. It defines types 'String_Id' and 'Symbol_Info', then creates 'String_Table' and 'Symbol_Table' as ordered maps. Finally, 'String_Info' is instantiated from 'Ordered_Join' using the previously defined tables, and a constant 'Apple_Info' is looked up using this joined mapping. ```Ada with Ada.Containers.Ordered_Maps; package Symbol_Package is type String_Id is ... type Symbol_Info is ... package String_Table is new Ada.Containers.Ordered_Maps (Key_Type => String, Element_Type => String_Id); package Symbol_Table is new Ada.Containers.Ordered_Maps (Key_Type => String_Id, Element_Type => Symbol_Info); package String_Info is new Ordered_Join(Mapping_1 => String_Table, Mapping_2 => Symbol_Table); Apple_Info : constant Symbol_Info := String_Info.Lookup("Apple"); end Symbol_Package; ``` -------------------------------- ### Ada Arithmetic Expression Examples Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-4-5-5.html Provides examples of various arithmetic expressions in Ada using integer, real, and fixed-point types, demonstrating operator precedence and type conversion. ```Ada I*J K/J K **mod** J X/Y F/2 3*F 0.75*G Fraction(F*G) Real(J)*Y ``` -------------------------------- ### Composing Pointer from Element_Array in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-B-3-2.html This Ada example demonstrates how to create a `Pointer` from the first element of an `Element_Array` using the `'Access` attribute. This is a common method for obtaining a pointer to an array's starting address for operations that require pointer types. ```Ada Some_Array : Element_Array(0..5) ; Some_Pointer : Pointer := Some_Array(0)'Access; ``` -------------------------------- ### Calling Procedures of Instantiated Generic Stacks in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-12-8.html This snippet illustrates how to invoke the procedures of the previously instantiated generic stack packages. It shows calls to the 'Push' procedure for both 'Stack_Int' and 'Stack_Bool', demonstrating the direct use of the package-qualified procedures after instantiation. ```Ada Stack_Int.Push(N); Stack_Bool.Push(True); ``` -------------------------------- ### Getting First Element Cursor in Ada Map Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-4.html The `First` function returns a cursor designating the first node in the `Container` map. If the `Container` is empty, it returns `No_Element`. This function provides a starting point for sequential traversal of the map. ```Ada function First (Container : Map) return Cursor; ``` -------------------------------- ### Instantiating Generic Stack Packages in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-12-8.html This snippet demonstrates how to create specific instances of the generic 'Stack' package. It shows two instantiations: 'Stack_Int' for integers with a capacity of 200, and 'Stack_Bool' for booleans with a capacity of 100. This illustrates how the generic parameters 'Size' and 'Item' are provided during instantiation. ```Ada package Stack_Int is new Stack(Size => 200, Item => Integer); package Stack_Bool is new Stack(100, Boolean); ``` -------------------------------- ### Instantiating Generic Stack Packages in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-12-8.html This Ada code demonstrates how to create instances of the generic `Stack` package. `Stack_Int` is instantiated with a size of 200 and `Integer` items, while `Stack_Bool` is instantiated with a size of 100 and `Boolean` items, showing both named and positional parameter associations. ```Ada package Stack_Int is new Stack(Size => 200, Item => Integer); package Stack_Bool is new Stack(100, Boolean); ``` -------------------------------- ### Demonstrating Generalized Indexing Calls in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-4-1-6.html This snippet illustrates different equivalent ways to perform generalized indexing on an `Indexed_Barrel` object. It shows traditional function calls, prefixed view calls, and various forms of implicit indexing and dereferencing, highlighting Ada's flexible syntax for container access. ```Ada Find (IB,"pear").Data.all := Element'(...); -- Traditional call IB.Find ("pear").Data.all := Element'(...); -- Call of prefixed view IB.Find ("pear") := Element'(...); -- Implicit dereference (see [4.1.5]) IB ("pear") := Element'(...); -- Implicit indexing and dereference IB ("pear").Data.all := Element'(...); -- Implicit indexing only ``` -------------------------------- ### Iterating Over Ada Environment Variables with For-Of Loop Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-5-5-3.html This snippet illustrates iterating over system environment variables using the 'for...of' loop in Ada. It uses Ada.Environment_Variables.Iterate to get pairs of Name and Val (value) for each variable and prints them. The '(<>)' parameter is noted as optional. ```Ada for (Name, Val) of Ada.Environment_Variables.Iterate(<>) loop -- "(<>)" is optional because it is the last parameter Put_Line (Name & " => " & Val); end loop; ``` -------------------------------- ### Examples of Ada Entry Calls Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-9-5-3.html This snippet provides various examples of entry calls in Ada, demonstrating different syntaxes including simple calls, calls with parameters, calls on array components, and indexed entry calls. These calls initiate a rendezvous with a task or protected object entry. ```Ada Agent.Shut_Down; Parser.Next_Lexeme(E); Pool(5).Read(Next_Char); Controller.Request(Low)(Some_Item); Flags(3).Seize; ``` -------------------------------- ### Accessing Upper Bound of Array Dimension in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-4-1-4.html This example demonstrates how to get the upper bound of a specific dimension of an array. Here, `'Last(2)` retrieves the upper bound of the second dimension of the `Board` array, useful for iterating or validating array indices. ```Ada Board'Last(2) ``` -------------------------------- ### Retrieving Memory Address of a Variable in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-4-1-4.html This example shows how to get the memory address of a record variable named `Message` using the `'Address` attribute. This attribute provides the storage address of an object, which is typically used for interfacing with hardware or low-level system programming. ```Ada Message'Address ``` -------------------------------- ### Instantiating Real_IO Package and Using It in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-10-9.html Demonstrates the instantiation of `Float_IO` for a `Real` type, creating `Real_IO`, and then uses a `use` clause to make its declarations directly visible. This sets up a specific I/O package for `Real` numbers, often with default formatting parameters. ```Ada package Real_IO is new Float_IO(Real); use Real_IO; ``` -------------------------------- ### Implementing a Generic Stack Package Body in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-12-8.html This Ada code provides the body for the generic `Stack` package. It implements the `Push` and `Pop` procedures using an internal array `Space` and an `Index` to track the top of the stack. It includes checks for stack overflow and underflow, raising the corresponding exceptions. ```Ada package body Stack is type Table is array (Positive range <>) of Item; Space : Table(1 .. Size); Index : Natural := 0; procedure Push(E : in Item) is begin if Index >= Size then raise Overflow; end if; Index := Index + 1; Space(Index) := E; end Push; procedure Pop(E : out Item) is begin if Index = 0 then raise Underflow; end if; E := Space(Index); Index := Index - 1; end Pop; end Stack; ``` -------------------------------- ### Examples of Direct Name Usage in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-4-1.html Illustrates various direct names in Ada, showing how simple identifiers can refer to different entities such as numbers, constants, scalar variables, array variables, types, functions, and exceptions. Each example demonstrates a basic identifier and its corresponding entity type. ```Ada Pi -- _the direct name of a number_ Limit -- _the direct name of a constant_ Count -- _the direct name of a scalar variable_ Board -- _the direct name of an array variable_ Matrix -- _the direct name of a type_ Random -- _the direct name of a function_ Error -- _the direct name of an exception_ ``` -------------------------------- ### Handling Layout Errors with Ada If-Elsif-Else Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-5-3.html This Ada example illustrates a multi-branch `if` statement using `elsif` and `else` clauses to handle different line conditions. If `Line_Too_Short` is true, it raises a `Layout_Error`. If `Line_Full` is true, it starts a `New_Line` and `Put`s an `Item`. Otherwise, it simply `Put`s the `Item`. This demonstrates cascading conditional logic. ```Ada if Line_Too_Short then raise Layout_Error; elsif Line_Full then New_Line; Put(Item); else Put(Item); end if; ``` -------------------------------- ### Instantiating Ada Packages with Formal Parameters Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-12-7.html This Ada code demonstrates the instantiation of generic packages, including the `Ordered_Join` package defined previously. It defines `Key_String`, `String_Id`, and `Symbol_Info` types, then instantiates `Ada.Containers.Ordered_Maps` to create `String_Table` and `Symbol_Table`. Finally, it instantiates `Ordered_Join` as `String_Info` by passing `String_Table` and `Symbol_Table` as formal package parameters, and shows an example lookup. ```Ada with Ada.Containers.Ordered_Maps; package Symbol_Package is subtype Key_String is String(1..5); type String_Id is ... type Symbol_Info is ... package String_Table is new Ada.Containers.Ordered_Maps (Key_Type => Key_String, Element_Type => String_Id); package Symbol_Table is new Ada.Containers.Ordered_Maps (Key_Type => String_Id, Element_Type => Symbol_Info); package String_Info is new Ordered_Join(Mapping_1 => String_Table, Mapping_2 => Symbol_Table); Apple_Info : constant Symbol_Info := String_Info.Lookup("Apple"); end Symbol_Package; ``` -------------------------------- ### Defining a Root Tagged Type and Procedure in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-6-3-1.html This Ada package `P` defines a base tagged type `Root` and a procedure `Proc` that operates on this type. This setup serves as a foundational example for demonstrating how calling conventions, particularly the `Intrinsic` convention, apply to inherited subprograms in generic contexts. ```Ada **package** P **is** **type** Root **is tagged null record**; **procedure** Proc(X: Root); **end** P; ``` -------------------------------- ### File Management Procedures in Ada.Direct_IO Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-8-4.html This section defines procedures for managing direct access files, including `Create` (to create and open a new file), `Open` (to open an existing file), `Close` (to close a file), `Delete` (to remove a file), and `Reset` (to re-initialize a file's mode or state). These procedures handle file lifecycle operations. ```Ada -- File management procedure Create(File : in out File_Type; Mode : in File_Mode := Inout_File; Name : in String := ""; Form : in String := ""); procedure Open (File : in out File_Type; Mode : in File_Mode; Name : in String; Form : in String := ""); procedure Close (File : in out File_Type); procedure Delete(File : in out File_Type); procedure Reset (File : in out File_Type; Mode : in File_Mode); procedure Reset (File : in out File_Type); ``` -------------------------------- ### Creating Reversible Iterator from Specific Position in Ada Vector Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-18-2.html This function returns a reversible iterator starting from a specified Start cursor within the Container. It propagates Program_Error if Start is invalid and Constraint_Error if Start is No_Element. The iterator allows forward or reverse traversal from the starting point and requires finalization. ```Ada function Iterate (Container : in Vector; Start : in Cursor) return Vector_Iterator_Interfaces.Reversible_Iterator'Class; ``` -------------------------------- ### Instantiating Generic Stack Type and Declaring Objects in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-12-8.html This snippet illustrates how to instantiate the `On_Stacks` generic package for a specific type (e.g., `Real`) and then declare a stack object (`S`) of the newly created generic type with a specified size. It also shows how to call the `Push` procedure on this stack object. ```Ada declare package Stack_Real is new On_Stacks(Real); use Stack_Real; S : Stack(100); begin ... Push(S, 2.54); ... end; ``` -------------------------------- ### Simulating Coin Tosses in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2012/RM-A-5-2.html This Ada example illustrates how to simulate coin tosses using `Ada.Numerics.Discrete_Random` with an enumeration type. It defines 'Coin' as (Heads, Tails), sets up a random generator, and demonstrates how to get a random coin toss result and process it using a case statement within a loop. ```Ada with Ada.Numerics.Discrete_Random; procedure Flip_A_Coin is type Coin is (Heads, Tails); package Random_Coin is new Ada.Numerics.Discrete_Random (Coin); use Random_Coin; G : Generator; begin Reset (G); -- Start the generator in a unique state in each run loop -- Toss a coin and process the result case Random(G) is when Heads => ... when Tails => ... end case; ... end loop; end Flip_A_Coin; ``` -------------------------------- ### Calling Ada Functions Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-6-4.html Shows examples of calling Ada functions. This includes a function call with multiple parameters, a function call without parameters, and an example of calling a function through an access-to-subprogram type, demonstrating different function invocation patterns. ```Ada Dot_Product(U, V) Clock F.all ``` -------------------------------- ### Example Usage of Common Ada Pragmas Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_2022/RM-2-8.html Demonstrates practical applications of several Ada pragmas, including `List` for controlling listing generation, `Optimize` for setting optimization criteria, `Assertion_Policy` for assertion checking, and `Assert` for runtime condition validation. These examples show how pragmas are used to influence compiler behavior and program execution. ```Ada pragma List(Off); -- turn off listing generation pragma Optimize(Off); -- turn off optional optimizations pragma Assertion_Policy(Check); -- check assertions pragma Assert(Exists(File_Name), Message => "Nonexistent file"); -- assert file exists ``` -------------------------------- ### Demonstrating Ada Comment Syntax and Usage Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-2-7.html This snippet illustrates various forms of comments in Ada, including standalone comments, end-of-line comments, and multi-line comments achieved through consecutive single-line comments. Comments in Ada start with two adjacent hyphens (`--`) and continue until the end of the line, providing a way to annotate code for clarity. ```Ada -- the last sentence above echoes the Algol 68 report end; -- processing of Line is complete -- a long comment can be split onto -- two or more consecutive lines ---------------- the first two hyphens start the comment ``` -------------------------------- ### Create Reversible Iterator for Ada Set from Start Cursor Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-18-9.html This function returns a reversible iterator object for the given `Container` set, starting from a specified `Start` cursor. It includes pre-conditions to ensure `Start` is not `No_Element` and that it refers to a valid element within the `Container`. ```Ada function Iterate (Container : in Set; Start : in Cursor) return Set_Iterator_Interfaces.Reversible_Iterator'Class with Pre => (Start /= No_Element or else raise Constraint_Error) and then (Has_Element (Container, Start) ``` -------------------------------- ### Example of Saving and Restoring Text_IO Current Output (Ada) Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/Defect2.html This Ada procedure P demonstrates a common pattern for saving and restoring Text_IO's current output file using File_Access. It opens a New_File, sets it as the current output, performs operations, then attempts to restore the Old_File_Ref. The example illustrates how an incorrect Text_IO implementation could cause the restoration to fail and lead to erroneous file operations. ```Ada procedure P(...) is New_File : File_Type; Old_File_Ref : constant File_Access := Current_Output; begin Open(New_File, ...); Set_Output(New_File); -- use the new file Set_Output(Old_File_Ref.all); Close(New_File); end P; ``` -------------------------------- ### Instantiating Integer_IO for Predefined Integer Type in Ada Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-A-10-8.html Demonstrates the instantiation of the generic `Ada.Text_IO.Integer_IO` package for the predefined `Integer` type, creating the nongeneric `Ada.Integer_Text_IO` package. This provides a convenient, ready-to-use package for standard integer input/output operations without requiring explicit generic instantiation. ```Ada with Ada.Text_IO; package Ada.Integer_Text_IO is new Ada.Text_IO.Integer_IO(Integer); ``` -------------------------------- ### Styling Example Div Elements in CSS Source: https://github.com/jquorning/hostarm/blob/primary/share/hostarm/ARM/Ada_202Y/AA-13-12-1.html This rule styles