❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Using Ada type Positive_Count as specified in Text_IO package

I am using GNAT's,2018, GPS on 1 2012 Macbook Pro, Intel Chip, for some Ada programming with IO to a terminal. I want to capture the cursor position, row, and column with Text_IO line and col functions returning to my variables of type Positive_count, declared in my package's specification, *.ids file, Compile fails with an ambiguous message about my line of code that calls line and col returning to Postiive_count type variables.

In Ada, specifying a Record’s Integer field as unbounded, probably box <> notation, in order to set the range when instantiating

Using GNAT CE with Ada on Macbook Intel silicon and want to specify (.ads) a record type with a type integer field, as unbounded,in order to set the record’s internet field’s range later, probably with box <> notation. But can’t get it right:

type a_gear is
record
num: Integer positive range <>;  -- fails     
position: Integer range <>) of integer; -- fails
end record;

Using Ada, using instance of Ada.Numerics.Generic_Elementary_Functions(Real), calculating Nth root and output same

Using Ada 2018 (increment of 2012), within a loop structure, I need to calculate the Nth root of Integers.

  1. In my package combinations.ads specification declaration (using GNAT GPS), I have
type Real           is digits 6;
  1. In package body combinations.adb, I have a procedure build, where before the begin, I instantiate Ada’s Generic_Elementary_Functions(Float), with
package Fermat_math is new
   Ada.Numerics.Generic_Elementary_Functions(Real)  ;
   use Fermat_math 

Later, in output section, I try:

-- -------------- buggy, fix
--   combo_sum_root := Fermat_math.Exp (Log (Integer(combo_sum_root) / n);  β€” n is integer type
     combo_sum_root := Real(combo_sum) ** (1/n) ; 
-- -------------

   put(" and sum's root is ");
   put(combo_sum_root'image );  β€”  -- gives all roots as 1.00000E+00

I had it working a few weeks back, with roots = 3.878… etc., but I lost that in careless version control.

Actual Code here:

β€” combinations.ads specification ------------------------------------------
with gearbox;
use  gearbox;
with Ada.Float_Text_IO  ; use Ada.Float_Text_IO;

with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics; use Ada.Numerics;

with Ada.Numerics.Elementary_Functions;
use  Ada.Numerics.Elementary_Functions;

package combinations is

type combo_action   is (add_element,clear, show, show_sum, Build);
type Real           is digits 6    ;

combo_sum_root      : Real         ;
i,n,b, combos_cnt
,combo_sum          : integer      ;

procedure get_parms                ;
Procedure build  (b,n,r:integer)   ;

end combinations;

-- combinations.adb BODY ---------------------------------------
with Text_IO              ;  use Text_IO;
with Ada.Text_IO          ;  use Ada.Text_IO;
with Ada.INteger_Text_IO  ;  use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded;  use Ada.Strings.UNbounded;
with gearbox              ;  use gearbox;
with Ada.Numerics.Generic_Elementary_Functions ;

package body combinations is

group, Intersection_count,r     : Integer              ;
done, get_value                 : boolean := false     ;
CR: constant Character := Character'Val (13)           ;
type gear_arrays is array(positive range <>) of integer;

-- ------------------------------------------------------------


procedure get_parms is
begin
...

 end get_parms ;

-- --------------------------------------------------
 procedure build  (b,n,r: Integer) is
-- --------------------------------------------------
cnt, e_cnt, value                : integer :=0      ;
launch, pause                    : character        ;
run_again                        : String := " "    ;
show_group                       : Unbounded_string ;
all_done, combo_done             : boolean := false ;
combo_sum_root                   : Real             ;
progress_string : Unbounded_String                  ;
gears:gear_array     (1..r)                         ;

-- with Ada.Numerics.Generic_Elementary_Functions   ;  β€” in specification .ads file
 package Fermat_math is new
  Ada.Numerics.Generic_Elementary_Functions(Real)  ;
 use Fermat_math                                   ;

begin
...
...

put("Selecting "); -- put(tot_combos, width=>1);
put(" Possible Combinations,"); New_line;
While Not all_done loop  -- for all/x combiNatioNs
 ...  
end loop;
   -- ------------------------
   combo_sum := 0;
   for e in  1..r loop  -- select r value, element of grou & size of combiatios
     value := fermats(gears(e).position,1);
     ...
   put ("Combination sum is "); put (combo_sum, width => 1);
  …..
  -- -------------- buggy, fix
--   combo_sum_root := Fermat_math.Exp (Log (Integer(combo_sum_root) / n);
 combo_sum_root := Real(combo_sum) ** (1/n) ; 
  -- -------------

   put(" and sum's root is ");
   put(combo_sum_root'image );  -- gives all roots as 1.00000E+00

   end loop;

     group := group + 1;  --
   end if;  -- is New group and shift
  end loop;  -- Not all doNe

 eNd build;
begin   -- package
 Null;
end combinations;

Defining a package with its sub units in Package Name?

I have run across code in Ncurses which defines packages with dot, "." subunits in the name, like this: Package body example.subunit1.subunit1 is .... .... end example;

Would I not just name the package "example" only and then later with example.subunit1; use example.subunit1;

OR does older Ada code (as found in Ncurses) have syntax to put a package's subunits in the package name?

❌
❌