From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: How do i print stuff?
Date: Sat, 28 Oct 2017 21:30:56 +0300
Date: 2017-10-28T21:30:56+03:00 [thread overview]
Message-ID: <f5k0n1F33baU1@mid.individual.net> (raw)
In-Reply-To: <f9da3284-c9ee-47c5-b176-f74fbd921b5e@googlegroups.com>
On 17-10-28 21:07 , tclwarrior@gmail.com wrote:
> Hi,
>
> This is my first day learning Ada
Heartily welcome!
...
> if c then
> Ada.Text_IO.Put_Line("true");
> else
> Ada.Text_IO.Put_Line("false");
> End if;
...
> But, I failed miserable to simply Print a, b and c
> well, I kind of succeeded in printing a and b using
> Float_Text_IO.Put
What do you mean "kind of" ? Text_IO is the "print" in Ada.
> But could not find a way to Print c (a boolean)
Boolean is an enumeration type, so the canonical way would be to create
an instance of the package Ada.Text_IO.Enumeration_IO for the Boolean
type, and use that. The instance will provide both input and output.
If all you need is to print a Boolean value, you can use the attribute
function Boolean'Image to convert a Boolean value to a string. Here
Boolean'Image (True) = "TRUE"
Boolean'Image (False) = "FALSE"
so you can do
Ada.Text_IO.Put_Line (Boolean'Image (c));
and get TRUE or FALSE printed.
> Well, so my question, that is the strategy to print stuff in Ada
> does have have a print statement that can print any type
No, there is no such print statement.
> does each type have his one print statement
In principle, yes; there are a set of generic packages that you can
instantiate to provide I/O for your types.
> How do I cast floats and booleans to strings?
Most scalar types have a 'Image attribute.
The inverse attribute is 'Value, which converts a string into a value.
For example, Boolean'Value ("TRUE") = True.
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2017-10-28 18:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-28 18:07 How do i print stuff? tclwarrior
2017-10-28 18:30 ` Niklas Holsti [this message]
2017-10-28 18:52 ` Niklas Holsti
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox