= 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 * https://www.adaic.org/resources/add_content/docs/craft/html/contents.htm == Hello world == '''hello.adb''' {{{#!highlight ada with Ada.Text_IO; -- comment procedure Hello is begin Ada.Text_IO.Put_Line("Hello, world!"); end Hello; }}} * gnat make hello.adb == Hello date == '''hellodate.adb''' {{{#!highlight ada with ada.text_io; use ada.text_io; with gnat.calendar.time_io; use gnat.calendar.time_io; with ada.calendar; use ada.calendar; procedure HelloDate is datetime: string(1..26); -- has exactly 26 chars begin -- gets date to string with milliseconds datetime := image( clock, "[%Y-%m-%dT%H:%M:%S.%i] " ); -- concatenetas string and shows date put_line( datetime & "stuff " ); end HelloDate; }}} * gnat make hellodate.adb == Person == '''person.ads''' {{{#!highlight ada -- The package encapsulates the type and code (functions,procedures) for the type. package Person is type Data is tagged private; -- constructor function Init(Name : in String; Address : in String) return Data; -- getter name function GetName(self : in Data; extra : in String) return String; -- getter address function GetAddress(self : in Data; extra : in String) return String; -- setter name procedure SetName(self : in out Data; name : in String); -- setter address procedure SetAddress(self : in out Data; address : in String); private type Data is tagged record Name : String (1 .. 10); Address : String (1 .. 10); end record; end Person; }}} '''person.adb''' {{{#!highlight ada package body Person is -- constructor function Init(Name : in String ; Address : in String) return Data is p : Person.Data;-- := (Name => Name , Address => Address); begin p.Name := Name; p.Address := Address; return p; end; -- getter name function GetName(self : in Data ; extra : in String) return String is begin return self.Name & extra; end; -- getter address function GetAddress(self : in Data ; extra : in String) return String is begin return self.Address & extra; end; -- setter name procedure SetName(self : in out Data ; name : String) is begin self.Name := name; end; -- setter address procedure SetAddress(self : in out Data ; address : String) is begin self.Address := address; end; end Person; }}} '''testperson.adb''' {{{#!highlight ada with ada.text_io; use ada.text_io; with Person; procedure TestPerson is p : Person.Data; q : Person.Data; begin p := Person.Init("0123456789", "9876543210"); q := Person.Init("aaaaaaaaaa", "bbbbbbbbbb"); q.SetName("zzzzzzzzzz"); put_line( p.GetName("ex1") & " " & p.GetAddress("ex3") ); put_line( q.GetName("ex2") & " " & q.GetAddress("ex4") ); end TestPerson; }}} * gnat make testperson.adb == Show file == '''show_file.adb''' {{{#!highlight ada with Ada.Text_IO; with Utils; with Ada.Command_Line; procedure Show_File is package acl renames Ada.Command_Line; package atio renames Ada.Text_IO; begin --Utils.Show_Content("/etc/hosts"); if acl.Argument_Count >= 1 then atio.Put_Line(acl.Argument(1)); Utils.Show_Content(acl.Argument(1)); else atio.Put_Line("Please insert the file name as an argument"); end if; end Show_File; }}} '''utils.ads''' {{{#!highlight ada package Utils is procedure Show_Content(File_Name: in String); end Utils; }}} '''utils.adb''' {{{#!highlight ada with Ada.Text_IO; package body Utils is procedure Show_Content(File_Name: in String) is package atio renames Ada.Text_IO; FileHandler : atio.File_Type; Text_Max_Size : Integer := 1024; Text : String(1 .. Text_Max_Size); Amount_Chars : Natural; begin atio.Open (FileHandler, Mode => atio.In_File, Name => File_Name); -- initialize the string for N in 1 .. Text_Max_Size loop Text(N) := '?'; end loop; while not atio.End_Of_File (FileHandler) loop atio.Get_Line(FileHandler, Text, Amount_Chars); for IDX in 1 .. Amount_Chars loop atio.Put( Text(IDX) ); end loop; --atio.Put_Line(Text); atio.New_Line; end loop; atio.Close(FileHandler); end; end Utils; }}} == Archive org - byte magazine == * https://archive.org/details/byte-magazine-1983-05/page/n419 * https://archive.org/details/byte-magazine-1983-05/page/n421 * https://archive.org/details/byte-magazine-1983-05/page/n423 * https://archive.org/details/byte-magazine-1983-12/page/n525 * https://archive.org/details/byte-magazine-1983-12/page/n527