Differences

This shows you the differences between two versions of the page.

Link to this comparison view

the_hello_world_program [2011/12/16 20:54]
thomaslocke
the_hello_world_program [2012/03/06 22:09] (current)
cvanvliet fixed a few grammar erros
Line 1: Line 1:
 =====  Introduction ​ ===== =====  Introduction ​ =====
-The worlds ​most famous program is probably the [[http://​en.wikibooks.org/​wiki/​Computer_Programming/​Hello_world|Hello,​ world!]] program. It is often the first program programmers write when starting on a new language, so it is only natural that we have an entire page dedicated to greeting the world in Ada.+The world'​s ​most famous program is probably the [[http://​en.wikibooks.org/​wiki/​Computer_Programming/​Hello_world|Hello,​ world!]] program. It is often the first program programmers write when starting on a new language, so it is only natural that we have an entire page dedicated to greeting the world in Ada.
  
 There are literally hundreds of ways to create a **Hello, world!** program in Ada. I'm going to show you a few of these, not because it's necessary to have more than one version, but because it allows me to demonstrate a few Ada basics. There are literally hundreds of ways to create a **Hello, world!** program in Ada. I'm going to show you a few of these, not because it's necessary to have more than one version, but because it allows me to demonstrate a few Ada basics.
Line 63: Line 63:
   hellowworld.gpr   hellowworld.gpr
  
-This all seems a bit "​much"​ for a simple **Hello, world!** program and it isn't absolutely necessary, but as this is Ada, we might as well do things properly from the beginningand that means keeping object files, executables,​ and source files separated.+This all seems a bit "​much"​ for a simple **Hello, world!** program and it isn't absolutely necessary, but as this is Ada, we might as well do things properly from the beginning and that means keeping object files, executables,​ and source files separated.
  
 Here's a quick overview of what we've got: Here's a quick overview of what we've got:
Line 70: Line 70:
   * **objects/​** When compiling a program, the compiler creates ALI files, object files and tree files. These files are placed in this directory.   * **objects/​** When compiling a program, the compiler creates ALI files, object files and tree files. These files are placed in this directory.
   * **helloworld.adb** The main Ada source file for the **Hello, world!** program.   * **helloworld.adb** The main Ada source file for the **Hello, world!** program.
-  * **helloworld.gpr** This is an Ada [[http://​gcc.gnu.org/​onlinedocs/​gcc-4.4.3/​gnat_ugn_unw/​Project-Files.html|project file]]. This file controls various properties of the program, such as how to compile it, what sources to include, where to put thingsand so on.+  * **helloworld.gpr** This is an Ada [[http://​gcc.gnu.org/​onlinedocs/​gcc-4.4.3/​gnat_ugn_unw/​Project-Files.html|project file]]. This file controls various properties of the program, such as how to compile it, what sources to include, where to put things and so on.
  
 =====  The project file  ===== =====  The project file  =====
Line 283: Line 283:
   !dlrow ,olleH   !dlrow ,olleH
  
-Lets go vertical:+Let'​s ​go vertical:
  
 <code ada> <code ada>
Line 316: Line 316:
 Neat! Neat!
  
-Lets take a closer look at the two programs. In both of them we have a //for// statement. This is a loop which allows for a specific number of iterations, here given by the //​Hello'​Range//​ discrete range. //​Hello'​Range//​ is just a short/​convenient way of saying //​Hello'​First .. Hello'​Last//,​ which would'​ve worked just as well.+Let'​s ​take a closer look at the two programs. In both of them we have a //for// statement. This is a loop which allows for a specific number of iterations, here given by the //​Hello'​Range//​ discrete range. //​Hello'​Range//​ is just a short/​convenient way of saying //​Hello'​First .. Hello'​Last//,​ which would'​ve worked just as well.
  
 We know that the //String// type is an array of characters, with an index value of the type //​Positive//​ We know that the //String// type is an array of characters, with an index value of the type //​Positive//​
Line 359: Line 359:
 In Ada the [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-2.html|Character type]] is an [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-1.html|enumeration type]]. The //'​Succ//​ attribute give the successor of an enumeration value, so the value //H// becomes an //I// instead. The //'​Pre//​ attribute gives the predecessor. In Ada the [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-2.html|Character type]] is an [[http://​www.adaic.com/​standards/​05rm/​html/​RM-3-5-1.html|enumeration type]]. The //'​Succ//​ attribute give the successor of an enumeration value, so the value //H// becomes an //I// instead. The //'​Pre//​ attribute gives the predecessor.
  
-====  Going UP or down  ====+====  Going up or down  ====
 Adding the package [[http://​www.adaic.com/​standards/​05rm/​html/​RM-A-3-2.html|Ada.Characters.Handling]] gives us a few tools to handle characters and strings, for example the ever useful ability to either change a string to uppercase or lowercase: Adding the package [[http://​www.adaic.com/​standards/​05rm/​html/​RM-A-3-2.html|Ada.Characters.Handling]] gives us a few tools to handle characters and strings, for example the ever useful ability to either change a string to uppercase or lowercase:
  
Line 428: Line 428:
 </​code>​ </​code>​
  
-Note how we at line 6 initialize the value of the //​HelloWorld//​ string to whitespace using the //others// aggregate. What //others// enables us to do is fill the remaining part of an array with the given value. In our case, the remaining part of the //​HelloWorld//​ array is the entire array, as we have not assigned a single character to the string.+Note how at line 6 initialize the value of the //​HelloWorld//​ string to whitespace using the //others// aggregate. What //others// enables us to do is fill the remaining part of an array with the given value. In our case, the remaining part of the //​HelloWorld//​ array is the entire array, as we have not assigned a single character to the string.
  
 Running this we get: Running this we get:

Navigation