Skip to content

Commit 45e6b8e

Browse files
Merge branch 'mr/320-new_hello_world_module' into 'master'
Resolve "Extract the "Hello World" Setup from the Overview Module" Closes #320 See merge request feng/training/material!386
2 parents 851d5e1 + 6ac865f commit 45e6b8e

17 files changed

+1043
-1
lines changed

courses/ada_essentials/010_overview.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ Overview
4242

4343
.. include:: 010_overview/01-a_little_history.rst
4444
.. include:: 010_overview/02-big_picture.rst
45-
.. include:: 010_overview/03-setup.rst
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
**************
2+
Hello World!
3+
**************
4+
5+
.. container:: PRELUDE BEGIN
6+
7+
.. container:: PRELUDE ROLES
8+
9+
.. role:: ada(code)
10+
:language: Ada
11+
12+
.. role:: C(code)
13+
:language: C
14+
15+
.. role:: cpp(code)
16+
:language: C++
17+
18+
.. role:: rust(code)
19+
:language: Rust
20+
21+
.. container:: PRELUDE SYMBOLS
22+
23+
.. |rightarrow| replace:: :math:`\rightarrow`
24+
.. |forall| replace:: :math:`\forall`
25+
.. |exists| replace:: :math:`\exists`
26+
.. |equivalent| replace:: :math:`\iff`
27+
.. |le| replace:: :math:`\le`
28+
.. |ge| replace:: :math:`\ge`
29+
.. |lt| replace:: :math:`<`
30+
.. |gt| replace:: :math:`>`
31+
.. |checkmark| replace:: :math:`\checkmark`
32+
33+
.. container:: PRELUDE REQUIRES
34+
35+
.. container:: PRELUDE PROVIDES
36+
37+
.. container:: PRELUDE END
38+
39+
.. include:: 013_hello_world/01-canonical_first_program.rst
40+
.. include:: 013_hello_world/88-lab.rst
41+
.. include:: 013_hello_world/99-summary.rst
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
=================
2+
Introducing Ada
3+
=================
4+
5+
-------------------------
6+
Canonical First Program
7+
-------------------------
8+
9+
"Hello World" - written in Ada!
10+
11+
.. container:: overlay 1
12+
13+
.. image:: hello_world_0.svg
14+
15+
.. container:: overlay 2
16+
17+
.. image:: hello_world_1.svg
18+
19+
.. container:: overlay 3
20+
21+
.. image:: hello_world_2.svg
22+
23+
.. container:: overlay 4
24+
25+
.. image:: hello_world_3.svg
26+
27+
.. container:: overlay 5
28+
29+
.. image:: hello_world_4.svg
30+
31+
.. container:: overlay 6
32+
33+
.. image:: hello_world_5.svg
34+
35+
.. container:: overlay 7
36+
37+
.. image:: hello_world_6.svg
38+
39+
.. container:: animate 2-
40+
41+
* :ada:`with` - package dependency (similar to ``import`` or ``#include``)
42+
43+
.. container:: animate 3-
44+
45+
* :ada:`--` - Comment (always goes to end of line)
46+
47+
.. container:: animate 4-
48+
49+
* :ada:`procedure` - subprogram declaration (name of subprogram is ``Hello_World``)
50+
51+
.. container:: animate 5-
52+
53+
* :ada:`begin` - used to start a block of statements
54+
55+
.. container:: animate 6-
56+
57+
* :ada:`Ada.Text_IO.Put_Line` is a subprogram that prints a string (it's defined
58+
in the package we specified on line 1)
59+
60+
.. container:: animate 7-
61+
62+
* :ada:`end` - used to end a block of statements. It's optional to add the
63+
name of the block you are ending
64+
65+
--------------------------------------
66+
Note on GNAT File Naming Conventions
67+
--------------------------------------
68+
69+
* GNAT compiler assumes one compilable entity per file
70+
71+
* Package specification, subprogram body, etc
72+
* So the body for :ada:`hello_world` should be the only thing in the file
73+
74+
* Filenames should match the name of the compilable entity
75+
76+
* Replacing "." with "-"
77+
* File extension is ".ads" for specifications and ".adb" for bodies
78+
* So the body for :ada:`hello_world` will be in :filename:`hello_world.adb`
79+
80+
* If there was a specification for the subprogram, it would be in :filename:`hello_world.ads`
81+
82+
* This is the **default** behavior. There are ways around both of these rules
83+
84+
* For further information, see Section 3.3 *File Naming Topics and Utilities* in the **GNAT User's Guide**
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
========
2+
Lab
3+
========
4+
5+
-----------------
6+
Hello World Lab
7+
-----------------
8+
9+
* This lab focuses more on running labs and verifying your setup
10+
11+
* Goal for this lab is to write an application that says :command:`Hello, World`
12+
13+
* Almost all our labs are the same. In each lab, we will
14+
15+
* Copy the appropriate :filename:`prompt` directory
16+
* Open the project that you just copied over
17+
* Make the changes necessary to perform the lab
18+
* Compile and run the lab
19+
* Compare the actual results to the expected results
20+
* Refer to the :filename:`answer` directory if you need help
21+
22+
* This particular lab will walk you through those steps
23+
24+
--------------------------
25+
Step 1 - Copy the Prompt
26+
--------------------------
27+
28+
* You should have downloaded (or received) a :filename:`labs`
29+
folder
30+
31+
* This folder contains a directory for each module in the
32+
class that has a lab
33+
34+
* In each module directory, you should find a :filename:`prompt`
35+
and :filename:`answer` folder
36+
37+
* The :filename:`prompt` folder contains
38+
39+
* Project file (:filename:`default.gpr`) that instructs
40+
the compilation system on how to build the application
41+
* Ada file(s) containing the source code for the application
42+
43+
* Create a folder for this class. As you do each lab, copy
44+
the module directory into the class folder
45+
46+
---------------------------
47+
Step 2 - Open the Project
48+
---------------------------
49+
50+
Using :toolname:`GNAT Studio`
51+
52+
* If :toolname:`GNAT Studio` is on your path, you can either
53+
54+
* Double-click the :filename:`default.gpr` project file
55+
* Run :command:`gnatstudio default.gpr` file from a command prompt in the correct folder
56+
57+
* Open the :toolname:`GNAT Studio` application
58+
59+
* :menu:`File` |rightarrow| :menu:`Open Project` to open the project file
60+
61+
-------------------------------------
62+
Step 3 - Make the Necessary Changes
63+
-------------------------------------
64+
65+
* In the left pane (**Project** tab if it not selected), expand the triangles until you
66+
see :filename:`hello_world.adb` - double-click it
67+
68+
* In our example, we want to follow the "prompt" comment on line 5
69+
70+
* On line 6, replace ``<something>`` with ``Hello, World``
71+
72+
----------------------------------
73+
Step 4 - Compile and Run the Lab
74+
----------------------------------
75+
76+
.. image:: compile_and_build_buttons.jpg
77+
78+
*(also available from* :menu:`Build` *menu)*
79+
80+
* After execution, search for the :menu:`Run` tab on the **Messages** window
81+
82+
-------------------------------------
83+
Step 5 - Compare Actual to Expected
84+
-------------------------------------
85+
86+
* If the actual results match the goal of the lab
87+
88+
* Congratulations - you've done it!
89+
* In this lab, we should see :command:`Hello, World` in the :menu:`Run` tab
90+
91+
* If they don't, go back to Step 3
92+
93+
* Or go on to Step 6
94+
95+
--------------------------------
96+
Step 6 - Looking at the Answer
97+
--------------------------------
98+
99+
* In the :filename:`answer` folder will be the source code for **a** correct solution
100+
101+
* Look at the part you think is most likely wrong
102+
103+
* Then go to Step 3 and see if that hint helps
104+
105+
* Continue until you get the expected result
106+
107+
* Even if that means copying the whole answer so you can understand it
108+
109+
* Even when you got it right yourself, looking at the answer may give you another
110+
method of solving the problem
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=========
2+
Summary
3+
=========
4+
5+
----------------------------
6+
First Steps in Writing Ada
7+
----------------------------
8+
9+
* **Hello, World** in Ada is just as simple as any other language
10+
11+
* Semantics and Syntax may be different, but concepts are similar
12+
13+
* We’ve taken the first step in speaking about some common concepts in Ada’s own language
14+
15+
* Comments
16+
* Subprograms
17+
* Code blocks
18+
* Input/Output (OK, only output so far!)
19+
20+
* On to the real work!
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Everyone's first program
2+
with Ada.Text_IO;
3+
procedure Hello_World is
4+
begin
5+
-- Replace '<something>' with 'Hello, World'
6+
Ada.Text_IO.Put_Line ("Hello, World");
7+
end Hello_World;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
project Default is
2+
for Main use ("hello_world.adb");
3+
end Default;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Everyone's first program
2+
with Ada.Text_IO;
3+
procedure Hello_World is
4+
begin
5+
-- Replace '<something>' with 'Hello, World'
6+
Ada.Text_IO.Put_Line ("<something>");
7+
end Hello_World;

courses/ada_essentials/standard_course.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
005_introduction.rst
22
010_overview.rst
3+
013_hello_world.rst
34
015_type_model.rst
45
020_declarations.rst
56
030_scalar_types.rst

images/compile_and_build_buttons.jpg

20.5 KB
Loading

0 commit comments

Comments
 (0)