comp.lang.ada
 help / color / mirror / Atom feed
* Text_io package's  Positive_Count type
@ 2023-01-11 10:14 Mace Ayres
  2023-01-11 13:52 ` Niklas Holsti
  0 siblings, 1 reply; 5+ messages in thread
From: Mace Ayres @ 2023-01-11 10:14 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Text_io package's Positive_Count type
  2023-01-11 10:14 Text_io package's Positive_Count type Mace Ayres
@ 2023-01-11 13:52 ` Niklas Holsti
  2023-01-11 21:04   ` Mace Ayres
  0 siblings, 1 reply; 5+ messages in thread
From: Niklas Holsti @ 2023-01-11 13:52 UTC (permalink / raw)


On 2023-01-11 12:14, Mace Ayres wrote:
> 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.

Please show the code that declares Positive_count, and the calls of Line 
and Col, and explain in which file they are located, and whether those 
files (or the corresponding .ads files) contain any "use" context-clauses.

Showing the compiler's error message would also be helpful. Usually an 
ambiguity problem means that there are several different subprograms 
with the same name, and the compiler does not know which one you want to 
call, because the types of the parameters and the result are not 
sufficiently constraining, or because the call does not qualify the 
subprogram name with a package name.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Text_io package's Positive_Count type
  2023-01-11 13:52 ` Niklas Holsti
@ 2023-01-11 21:04   ` Mace Ayres
  2023-01-11 21:42     ` Niklas Holsti
  2023-01-11 21:46     ` Jeffrey R.Carter
  0 siblings, 2 replies; 5+ messages in thread
From: Mace Ayres @ 2023-01-11 21:04 UTC (permalink / raw)


-- combinations.ads -- physical file
with gearbox; use  gearbox;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Term_IO;              use TERM_IO;
with Text_IO;                use Text_IO;
package combinations is
...
col_is : Positive_Count ;  -- types from Text_IO
row_is : Positive_Count ;
procedure build;
...
end combinations;
-- *************************************
-- combinations.adb -- physical file
package body combination is
....
procedure build is
..
begin
...
put(" Row is " );   put(row_is);
put(" Column is "); put(col_is);
...
end combinations;

-- *****************************
compiler error
line_no : no candidate interpretations match the actual:
     missing argument for parameter 'Item' in call to "put"
    ...
  possible missing instantiation of Text_IO.Integer_IO
  expected type "Standard Integer"
  found type Ada.Text_IO.count

____
This is different error than before and I easily see Put() is expecting Integer but has the.. count type; so I need some sort of translation to satisfy put(), maybe with and use Text_IO.Integer_IO as error message suggest?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Text_io package's Positive_Count type
  2023-01-11 21:04   ` Mace Ayres
@ 2023-01-11 21:42     ` Niklas Holsti
  2023-01-11 21:46     ` Jeffrey R.Carter
  1 sibling, 0 replies; 5+ messages in thread
From: Niklas Holsti @ 2023-01-11 21:42 UTC (permalink / raw)


On 2023-01-11 23:04, Mace Ayres wrote:
> -- combinations.ads -- physical file
> with gearbox; use  gearbox;
> with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
> with Term_IO;              use TERM_IO;
> with Text_IO;                use Text_IO;
> package combinations is
> ...
> col_is : Positive_Count ;  -- types from Text_IO
> row_is : Positive_Count ;
> procedure build;
> ...
> end combinations;
> -- *************************************
> -- combinations.adb -- physical file
> package body combination is
> ....
> procedure build is
> ..
> begin
> ...
> put(" Row is " );   put(row_is);
> put(" Column is "); put(col_is);
> ...
> end combinations;
> 
> -- *****************************
> compiler error
> line_no : no candidate interpretations match the actual:
>       missing argument for parameter 'Item' in call to "put"
>      ...
>    possible missing instantiation of Text_IO.Integer_IO
>    expected type "Standard Integer"
>    found type Ada.Text_IO.count


Thanks for showing the code (although it seems you have changed it since 
you asked the question originally).


> ____
> This is different error than before and I easily see Put() is
> expecting Integer but has the.. count type; so I need some sort of
> translation to satisfy put(), maybe with and use Text_IO.Integer_IO
> as error message suggest?


Well, yes. But note that the message says you should _instantiate_ 
Text_IO.Integer_IO, not "with" it. This is because Text_IO.Integer_IO is 
not its own library unit, but a generic package nested within Text_IO, 
which you already "withed". So the message suggests that you should do 
this, somewhere in the declaration part of the body of package combination:

    package Count_IO is new Text_IO.Integer_IO (Num => Positive_Count);

and then you can call

    Count_IO.Put (row_is);

and so forth. Or, if you add "use Count_IO" after the instantiation, you 
can write just Put (row_is).

However, the simplest method for occasional or debugging output is to 
use the 'Image attribute to convert a number to text, as for example

    Put (row_is'Image);

or (for older Ada versions)

   Put (Positive_Count'Image (row_is));

where the "Put" is the Put in Text_IO for strings. With 'Image, you 
don't need Text_IO.Integer_IO (but you have less control over the form 
of the output).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Text_io package's Positive_Count type
  2023-01-11 21:04   ` Mace Ayres
  2023-01-11 21:42     ` Niklas Holsti
@ 2023-01-11 21:46     ` Jeffrey R.Carter
  1 sibling, 0 replies; 5+ messages in thread
From: Jeffrey R.Carter @ 2023-01-11 21:46 UTC (permalink / raw)


On 2023-01-11 22:04, Mace Ayres wrote:
> ____
> This is different error than before and I easily see Put() is expecting Integer but has the.. count type; so I need some sort of translation to satisfy put(), maybe with and use Text_IO.Integer_IO as error message suggest?

Ada.Text_IO.Integer_IO is a generic package that you would instantiate with 
Ada.Text_IO.Positive_Count. The instantiation would then have a Put procedure 
for Positive_Count.

Alternatively, you could use Positive_Count'Image to convert your values into 
Strings that may be used directly with Ada.Text_IO.Put.

-- 
Jeff Carter
"You me on the head hitted."
Never Give a Sucker an Even Break
108

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-11 21:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 10:14 Text_io package's Positive_Count type Mace Ayres
2023-01-11 13:52 ` Niklas Holsti
2023-01-11 21:04   ` Mace Ayres
2023-01-11 21:42     ` Niklas Holsti
2023-01-11 21:46     ` Jeffrey R.Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox