• Re: Integer_IO or Modular_IO with different base as default

    From Simon Wright@21:1/5 to Ken Roberts on Mon Nov 15 21:40:30 2021
    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#

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ken Roberts@21:1/5 to All on Mon Nov 15 14:09:48 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Ken Roberts on Mon Nov 15 22:13:28 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ken Roberts@21:1/5 to All on Mon Nov 15 13:27:01 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeffrey R.Carter@21:1/5 to Ken Roberts on Tue Nov 16 00:10:05 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ken Roberts@21:1/5 to Ken Roberts on Thu Nov 18 16:06:42 2021
    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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)