comp.lang.ada
 help / color / mirror / Atom feed
* Integer_IO or Modular_IO with different base as default
@ 2021-11-15 21:27 Ken Roberts
  2021-11-15 21:40 ` Simon Wright
  2021-11-15 22:13 ` Ben Bacarisse
  0 siblings, 2 replies; 6+ messages in thread
From: Ken Roberts @ 2021-11-15 21:27 UTC (permalink / raw)


I've been trying to look at how to instantiate Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO with a different base as default (base 8 for a project I'm playing with while learning).

So far, the only thing I can find is instantiate with a different integer (or mod number), but the base is always defined as 10.

I'd like to output numbers for the project in base 8 (octal) in keeping with the documentation on how the digital system works.

Does anyone have an idea on how to instantiate Integer_IO (or Modular_IO) with Default_Base := 8 ?

So far, the only thing I've been able to work with is copy Ada.Text_IO.Integer_IO (or Modular_IO) in my project as a different package with the only change being the Default_Base parameter.

Any help with noob questions would be appreciated.

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

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 21:27 Integer_IO or Modular_IO with different base as default Ken Roberts
@ 2021-11-15 21:40 ` Simon Wright
  2021-11-15 22:09   ` Ken Roberts
  2021-11-15 22:13 ` Ben Bacarisse
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Wright @ 2021-11-15 21:40 UTC (permalink / raw)


Ken Roberts <alisonken1@gmail.com> writes:

> I've been trying to look at how to instantiate Ada.Text_IO.Integer_IO
> and Ada.Text_IO.Modular_IO with a different base as default (base 8
> for a project I'm playing with while learning).
>
> So far, the only thing I can find is instantiate with a different
> integer (or mod number), but the base is always defined as 10.
>
> I'd like to output numbers for the project in base 8 (octal) in
> keeping with the documentation on how the digital system works.

You can't change Default_Base, but you can specify the base in which to
output the number, as in ARM A.10.8(11):

   procedure Put(File  : in File_Type;
                 Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

   procedure Put(Item  : in Num;
                 Width : in Field := Default_Width;
                 Base  : in Number_Base := Default_Base);

e.g.

   Put (10, Base => 8);

outputs

   8#12#

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

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 21:40 ` Simon Wright
@ 2021-11-15 22:09   ` Ken Roberts
  2021-11-15 23:10     ` Jeffrey R.Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Ken Roberts @ 2021-11-15 22:09 UTC (permalink / raw)


On Monday, November 15, 2021 at 1:40:34 PM UTC-8, Simon Wright wrote:
< snip >
I was going to add before your reply that I'm trying to get output without the extra padding of showing the base.

I would rather not have to send the output to a subroutine that would strip the extra characters out or write a new routine to convert the decimal to octal before printing.

It's more in keeping with the system design of the original digital equipment as well as the documentation that 

As an example, the format as documented for the equipment:

Data word: DDDDD DDDDD (30-bit word in octal data format)
Instruction word: FF J K B DDDDD (30-bit word in octal instruction 1 format)
Instruction word: FF JJ K B DDDDD (30-bit word in octal instruction 2 format)

All of the documentation is written in those formats, and having 8X..X surrounding each field really sucks on the output when trying to evaluate between original documentation and the program output.

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

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 21:27 Integer_IO or Modular_IO with different base as default Ken Roberts
  2021-11-15 21:40 ` Simon Wright
@ 2021-11-15 22:13 ` Ben Bacarisse
  1 sibling, 0 replies; 6+ messages in thread
From: Ben Bacarisse @ 2021-11-15 22:13 UTC (permalink / raw)


Ken Roberts <alisonken1@gmail.com> writes:

> Does anyone have an idea on how to instantiate Integer_IO (or
> Modular_IO) with Default_Base := 8 ?

Instantiate Integer_IO and then assign Default_Base := 8:

with Ada.Text_IO; use Ada.Text_IO;
procedure Oct is
  package Oct_IO is new Integer_IO(Integer);
begin
  Oct_IO.Default_Base := 8;
  Oct_IO.Put(16);
end Oct;

(Add "use Oct_IO;" if you prefer.)

I don't think there is a way to do this on instantiation so that
Default_Base is 8 and can't be changed, which would be nice.  (Note: my
Ada is /very/ rusty.  Take /anyone's/ answer over mine about this!)

-- 
Ben.

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

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 22:09   ` Ken Roberts
@ 2021-11-15 23:10     ` Jeffrey R.Carter
  2021-11-19  0:06       ` Ken Roberts
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R.Carter @ 2021-11-15 23:10 UTC (permalink / raw)


On 2021-11-15 23:09, Ken Roberts wrote:
> I was going to add before your reply that I'm trying to get output without the extra padding of showing the base.

Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO both declare

      Default_Base  : Number_Base := 10;

This is a variable, so you can change it.

However, that outputs in based-literal format.

You can use PragmARC.Images (https://github.com/jrcarter/PragmARC) to 
obtain images in any base without the base information. Image width and 
zero filling are also provided.

-- 
Jeff Carter
"I spun around, and there I was, face to face with a
six-year-old kid. Well, I just threw my guns down and
walked away. Little bastard shot me in the ass."
Blazing Saddles
40

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

* Re: Integer_IO or Modular_IO with different base as default
  2021-11-15 23:10     ` Jeffrey R.Carter
@ 2021-11-19  0:06       ` Ken Roberts
  0 siblings, 0 replies; 6+ messages in thread
From: Ken Roberts @ 2021-11-19  0:06 UTC (permalink / raw)


Sorry for the delay in getting back - $DAYJOB and $ILLNESS combined.

On Mon, Nov 15, 2021 at 3:10 PM Jeffrey R.Carter <deleted> wrote:
On 2021-11-15 23:09, Ken Roberts wrote:
> I was going to add before your reply that I'm trying to get output without the extra padding of showing the base.

Ada.Text_IO.Integer_IO and Ada.Text_IO.Modular_IO both declare

      Default_Base  : Number_Base := 10;

This is a variable, so you can change it.

However, that outputs in based-literal format.

You can use PragmARC.Images (https://github.com/jrcarter/PragmARC) to
obtain images in any base without the base information. Image width and
zero filling are also provided.

--
Jeff Carter

Hmmm. After testing by setting the base manually after instantiation, still adds the based-literal information as noted.

So, it's either copy Modular_IO into my project (with renaming) and change the default base, or add another package to monitor for updates.

Fun either way.

Thanks for the help both Jeff and Ben. (Sincerely, not ironically).

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

end of thread, other threads:[~2021-11-19  0:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 21:27 Integer_IO or Modular_IO with different base as default Ken Roberts
2021-11-15 21:40 ` Simon Wright
2021-11-15 22:09   ` Ken Roberts
2021-11-15 23:10     ` Jeffrey R.Carter
2021-11-19  0:06       ` Ken Roberts
2021-11-15 22:13 ` Ben Bacarisse

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