MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 15 as of 2019-07-18 22:40:11
  • Ada

Ada

  • https://en.wikibooks.org/wiki/Ada_Programming

  • https://en.wikibooks.org/wiki/Ada_Programming/Basic

  • https://craftofcoding.files.wordpress.com/2013/07/ada_strings.pdf

  • https://www.adaic.org/resources/add_content/standards/05rm/html/RM-TOC.html

  • https://ada-util.readthedocs.io/en/latest/Util_Dates/

  • https://en.wikibooks.org/wiki/Ada_Programming/Libraries/GNAT.Calendar.Time_IO

  • https://www.tutorialspoint.com/compile_ada_online.php

  • https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/the_gnat_library.html

Hello world

hello.adb

   1 with Ada.Text_IO;
   2 -- comment 
   3 procedure Hello is
   4 begin
   5    Ada.Text_IO.Put_Line("Hello, world!");
   6 end Hello;
  • gnat make hello.adb

Hello date

hellodate.adb

   1 with ada.text_io;
   2 use ada.text_io;
   3 with gnat.calendar.time_io;
   4 use gnat.calendar.time_io;
   5 with ada.calendar;
   6 use ada.calendar;
   7 
   8 procedure HelloDate is
   9     datetime: string(1..26); -- has exactly 26 chars
  10 begin
  11     -- gets date to string with milliseconds
  12     datetime := image( clock, "[%Y-%m-%dT%H:%M:%S.%i] " );
  13     -- concatenetas string and shows date
  14     put_line( datetime & "stuff " );  
  15 end HelloDate;
  • gnat make hellodate.adb

Person

person.ads

   1 -- The package encapsulates the type and code (functions,procedures) for the type.
   2 package Person is
   3    type Data is tagged private;
   4    -- constructor
   5    function Init(Name : in String; Address : in String) return Data;
   6    -- getter name
   7    function GetName(self : in Data; extra : in String) return String;
   8    -- getter address
   9    function GetAddress(self : in Data; extra : in String) return String;
  10    -- setter name
  11    procedure SetName(self : in out Data; name : in String);
  12    -- setter address
  13    procedure SetAddress(self : in out Data; address : in String);
  14    
  15    private 
  16      type Data is tagged 
  17        record
  18          Name : String (1 .. 10);
  19          Address : String (1 .. 10);
  20        end record;
  21    
  22 end Person;

person.adb

   1 package body Person is
   2 
   3    -- constructor
   4    function Init(Name : in String ; Address : in String) return Data is
   5       p : Person.Data;-- := (Name => Name , Address => Address);
   6    begin 
   7      p.Name := Name;
   8      p.Address := Address;
   9      return p;
  10    end;
  11 
  12    -- getter name
  13    function GetName(self : in Data ; extra : in String) return String is
  14    begin
  15      return self.Name & extra;
  16    end;
  17 
  18    -- getter address
  19    function GetAddress(self : in Data ; extra : in String) return String is
  20    begin
  21      return self.Address & extra;
  22    end;
  23 
  24    -- setter name
  25    procedure SetName(self : in out Data ; name : String) is
  26    begin
  27      self.Name := name;
  28    end;
  29 
  30    -- setter address
  31    procedure SetAddress(self : in out Data ; address : String) is
  32    begin
  33      self.Address := address;
  34    end;
  35    
  36 end Person;

testperson.adb

   1 with ada.text_io;
   2 use ada.text_io;
   3 with Person;
   4 
   5 procedure TestPerson is
   6   p : Person.Data;
   7   q : Person.Data;
   8 begin
   9   p := Person.Init("0123456789", "9876543210");
  10   q := Person.Init("aaaaaaaaaa", "bbbbbbbbbb");
  11   q.SetName("zzzzzzzzzz");
  12 
  13   put_line( p.GetName("ex1") & " " & p.GetAddress("ex3") );
  14   put_line( q.GetName("ex2") & " " & q.GetAddress("ex4") );
  15 end TestPerson;
  • gnat make testperson.adb
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01