Skip to content

Commit

Permalink
Editorial changes: adding compile button to source-code blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
gusthoff committed Feb 20, 2021
1 parent 5b0009f commit 9d56419
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion content/courses/intro-to-ada/chapters/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Ada exceptions are not types, but instead objects, which may be
peculiar to you if you're used to the way Java or Python support
exceptions. Here's how you declare an exception:

.. code:: ada no_button project=Courses.Intro_To_Ada.Exceptions.Show_Exception
.. code:: ada compile_button project=Courses.Intro_To_Ada.Exceptions.Show_Exception

package Exceptions is
My_Except : exception;
Expand Down
8 changes: 4 additions & 4 deletions content/courses/intro-to-ada/chapters/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ by using the keyword :ada:`generic`. For example:
.. raph-amiard: We are lacking a definition/link of metaprogramming.


.. code:: ada no_button project=Courses.Intro_To_Ada.Generics.Show_Simple_Generic
.. code:: ada compile_button project=Courses.Intro_To_Ada.Generics.Show_Simple_Generic

generic
type T is private;
Expand All @@ -37,7 +37,7 @@ want to create an algorithm that works on any integer type, or even on
any type at all, whether a numeric type or not. The following example
declares a formal type :ada:`T` for the :ada:`Set` procedure.

.. code:: ada no_button project=Courses.Intro_To_Ada.Generics.Show_Formal_Type_Declaration
.. code:: ada compile_button project=Courses.Intro_To_Ada.Generics.Show_Formal_Type_Declaration

generic
type T is private;
Expand Down Expand Up @@ -71,7 +71,7 @@ Formal object declaration
Formal objects are similar to subprogram parameters. They can reference
formal types declared in the formal specification. For example:

.. code:: ada no_button project=Courses.Intro_To_Ada.Generics.Show_Formal_Object_Declaration
.. code:: ada compile_button project=Courses.Intro_To_Ada.Generics.Show_Formal_Object_Declaration

generic
type T is private;
Expand All @@ -95,7 +95,7 @@ We don't repeat the :ada:`generic` keyword for the body declaration of a
generic subprogram or package. Instead, we start with the actual
declaration and use the generic types and objects we declared. For example:

.. code:: ada no_button project=Courses.Intro_To_Ada.Generics.Show_Generic_Body_Definition
.. code:: ada compile_button project=Courses.Intro_To_Ada.Generics.Show_Generic_Body_Definition

generic
type T is private;
Expand Down
12 changes: 6 additions & 6 deletions content/courses/intro-to-ada/chapters/imperative_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ and subprogram parameter modes.

Ada's :ada:`if` statement is pretty unsurprising in form and function:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Expand Down Expand Up @@ -156,7 +156,7 @@ integer value).
Here's a slight variation on the example, which illustrates an :ada:`if` statement
with an :ada:`else` part:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive_2
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive_2

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Expand All @@ -180,7 +180,7 @@ displays the value followed by the String " is not a positive number".
Our final variation illustrates an :ada:`if` statement with :ada:`elsif`
sections:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Direction
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Direction

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Expand Down Expand Up @@ -418,7 +418,7 @@ but with some important differences.
Here's an example, a variation of a program that was shown earlier
with an :ada:`if` statement:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Direction_2
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Direction_2

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Expand Down Expand Up @@ -542,7 +542,7 @@ A declaration cannot appear as a statement. If you need to declare a local
variable amidst the statements, you can introduce a new declarative region with
a block statement:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Greet_6
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Greet_6

with Ada.Text_IO; use Ada.Text_IO;

Expand Down Expand Up @@ -589,7 +589,7 @@ If expressions
Here's an alternative version of an example we saw earlier; the :ada:`if`
statement has been replaced by an :ada:`if` expression:

.. code:: ada no_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive
.. code:: ada compile_button project=Courses.Intro_To_Ada.Imperative_Language.Check_Positive

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Expand Down
22 changes: 11 additions & 11 deletions content/courses/intro-to-ada/chapters/modular_programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Packages

Here is an example of a package declaration in Ada:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Week
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Week

package Week is

Expand Down Expand Up @@ -151,7 +151,7 @@ declarations and no body. That's not a mistake: in a package specification,
which is what is illustrated above, you cannot declare bodies. Those have to be
in the package body.

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Operations
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Operations

package Operations is

Expand Down Expand Up @@ -253,7 +253,7 @@ is called :ada:`Text_IO`. In the previous examples, we've been using the
Let's begin our discussion on child packages by taking our previous
:ada:`Week` package:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package Week is

Expand All @@ -269,7 +269,7 @@ Let's begin our discussion on child packages by taking our previous

If we want to create a child package for :ada:`Week`, we may write:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package Week.Child is

Expand All @@ -280,7 +280,7 @@ If we want to create a child package for :ada:`Week`, we may write:
Here, :ada:`Week` is the parent package and :ada:`Child` is the child
package. This is the corresponding package body of :ada:`Week.Child`:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package body Week.Child is

Expand Down Expand Up @@ -323,7 +323,7 @@ the hierarchy of the previous source-code example by declaring a
be the parent of the :ada:`Grandchild` package. Let's consider this
implementation:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package Week.Child.Grandchild is

Expand Down Expand Up @@ -365,7 +365,7 @@ So far, we've seen a single child package of a parent package. However, a
parent package can also have multiple children. We could extend the example
above and implement a :ada:`Week.Child_2` package. For example:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package Week.Child_2 is

Expand All @@ -379,7 +379,7 @@ but it's also the parent of the :ada:`Child_2` package. In the same way,

This is the corresponding package body of :ada:`Week.Child_2`:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Child_Packages

package body Week.Child_2 is

Expand Down Expand Up @@ -414,7 +414,7 @@ for elements declared in the package body of a parent package.
Let's consider the package :ada:`Book` and its child
:ada:`Additional_Operations`:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility

package Book is

Expand All @@ -436,7 +436,7 @@ Let's consider the package :ada:`Book` and its child

This is the body of both packages:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility

package body Book is

Expand Down Expand Up @@ -486,7 +486,7 @@ implementation of the :ada:`Get_Extended_Author` function to retrieve this
string. Likewise, we can use this strategy to implement the
:ada:`Get_Extended_Title` function. This is the adapted code:

.. code:: ada no_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility
.. code:: ada compile_button project=Courses.Intro_To_Ada.Modular_Programming.Visibility

package body Book.Additional_Operations is

Expand Down
28 changes: 14 additions & 14 deletions content/courses/intro-to-ada/chapters/more_about_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ convenient:
However, note that as soon as you used a named association, all subsequent
components likewise need to be specified with names associations.

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Points
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Points

package Points is
type Point is record
Expand All @@ -73,7 +73,7 @@ in the section on :ref:`enumeration types <EnumTypes>`.
Let's take a simple example: it is possible in Ada to have functions that have
the same name, but different types for their parameters.

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Overloading
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Overloading

package Pkg is
function F (A : Integer) return Integer;
Expand All @@ -87,7 +87,7 @@ overloading.
One of the novel aspects of Ada's overloading facility is the ability to
resolve overloading based on the return type of a function.

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Overloading
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Overloading

package Pkg is
type SSID is new Integer;
Expand Down Expand Up @@ -150,7 +150,7 @@ This is where a qualified expression becomes useful.
Syntactically the target of a qualified expression can be either any expression
in parentheses, or an aggregate:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Qual_Expr
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Qual_Expr

package Qual_Expr is
type Point is record
Expand Down Expand Up @@ -211,7 +211,7 @@ pointers:

Here is how you declare a simple pointer type, or access type, in Ada:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types

package Dates is
type Months is (January, February, March, April, May, June, July,
Expand Down Expand Up @@ -295,7 +295,7 @@ Once we have declared an access type, we need a way to give variables of the
types a meaningful value! You can allocate a value of an access type
with the :ada:`new` keyword in Ada.

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types

with Dates; use Dates;

Expand All @@ -309,7 +309,7 @@ with the :ada:`new` keyword in Ada.
If the type you want to allocate needs constraints, you can put them in the
subtype indication, just as you would do in a variable declaration:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types

with Dates; use Dates;

Expand All @@ -327,7 +327,7 @@ In some cases, though, allocating just by specifying the type is not ideal, so
Ada also allows you to initialize along with the allocation. This is done via
the qualified expression syntax:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types

with Dates; use Dates;

Expand All @@ -348,7 +348,7 @@ pointer. Dereferencing a pointer uses the :ada:`.all` syntax in Ada, but is
often not needed - in many cases, the access value will be implicitly
dereferenced for you:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Access_Types

with Dates; use Dates;

Expand Down Expand Up @@ -417,7 +417,7 @@ naturally defined through two types, a record type and an access type, that are
mutually dependent. To declare mutually dependent types, you can use an
incomplete type declaration:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Simple_List
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Simple_List

package Simple_List is
type Node;
Expand Down Expand Up @@ -448,7 +448,7 @@ known at compile time. This is illustrated in the example below:
.. ?? an elaboration pragma is used.
.. ?? Consider simplifying or restructuring the example to avoid this issue

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Var_Size_Record
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Var_Size_Record

package Runtime_Length is
function Compute_Max_Len return Natural;
Expand Down Expand Up @@ -487,7 +487,7 @@ different sizes.
You can get analogous functionality for records, too, using a special kind of
field that is called a discriminant:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Var_Size_Record_2
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Var_Size_Record_2

package Var_Size_Record_2 is
type Items_Array is array (Positive range <>) of Integer;
Expand Down Expand Up @@ -571,7 +571,7 @@ However, discriminants can also be used to obtain the functionality of what are
sometimes called "variant records": records that can contain different sets of
fields.

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Variant_Record
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Variant_Record

package Variant_Record is
type Expr; -- Forward declaration of Expr
Expand Down Expand Up @@ -799,7 +799,7 @@ fixed-point data types |mdash| you can find more details in this discussion
about the `Q format <https://en.wikipedia.org/wiki/Q_(number_format)>`_.
We may also rewrite this code with an exact type definition:

.. code:: ada no_button project=Courses.Intro_To_Ada.More_About_Types.Normalized_Adapted_Fixed_Point_Type
.. code:: ada compile_button project=Courses.Intro_To_Ada.More_About_Types.Normalized_Adapted_Fixed_Point_Type

procedure Normalized_Adapted_Fixed_Point_Type is
type TQ31 is delta 2.0 ** (-31) range -1.0 .. 1.0 - 2.0 ** (-31);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ brushed on, but not really covered, up to now:
You can create one or more new types from every type in Ada. Type
derivation is built into the language.

.. code:: ada no_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Newtypes
.. code:: ada compile_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Newtypes

package Newtypes is
type Point is record
Expand Down Expand Up @@ -184,7 +184,7 @@ functionality is added:

Let's see our first tagged type declarations:

.. code:: ada no_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Types
.. code:: ada compile_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Types

package P is
type My_Class is tagged null record;
Expand Down Expand Up @@ -433,8 +433,7 @@ applied to tagged types, as we'll see in this section.

This is an example of a tagged private type:

.. code:: ada no_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Private_Types
:class: ada-syntax-only
.. code:: ada compile_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Private_Types

package P is
type T is tagged private;
Expand All @@ -446,8 +445,7 @@ This is an example of a tagged private type:

This is an example of a tagged limited type:

.. code:: ada no_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Limited_Types
:class: ada-syntax-only
.. code:: ada compile_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Tagged_Limited_Types

package P is
type T is tagged limited record
Expand Down Expand Up @@ -512,8 +510,7 @@ In this section, we'll discuss an useful pattern for object-oriented programming
in Ada: classwide access type. Let's start with an example where we declare a
tagged type :ada:`T` and a derived type :ada:`T_New`:

.. code:: ada no_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Classwide_Error
:class: ada-syntax-only
.. code:: ada compile_button project=Courses.Intro_To_Ada.Object_Oriented_Programming.Classwide_Error

package P is
type T is tagged null record;
Expand Down
2 changes: 1 addition & 1 deletion content/courses/intro-to-ada/chapters/privacy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Abstract data types
With this high-level granularity, it might not seem obvious how to hide the
implementation details of a type. Here is how it can be done in Ada:

.. code:: ada no_button project=Courses.Intro_To_Ada.Privacy.Stacks
.. code:: ada compile_button project=Courses.Intro_To_Ada.Privacy.Stacks

package Stacks is
type Stack is private;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Instantiation
Here's an example showing the instantiation and declaration of a
vector :ada:`V`:

.. code:: ada no_button project=Courses.Intro_To_Ada.Standard_Library.Show_Vector_Inst
.. code:: ada compile_button project=Courses.Intro_To_Ada.Standard_Library.Show_Vector_Inst

with Ada.Containers.Vectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The :ada:`Ada.Numerics.Elementary_Functions` package provides common
operations for floating-point types, such as square root, logarithm,
and the trigonometric functions (e.g., sin, cos). For example:

.. code:: ada no_button project=Courses.Intro_To_Ada.Standard_Library.Show_Elem_Math
.. code:: ada run_button project=Courses.Intro_To_Ada.Standard_Library.Show_Elem_Math

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics; use Ada.Numerics;
Expand Down
Loading

0 comments on commit 9d56419

Please sign in to comment.