* HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io
@ 2015-10-26 10:21 comicfanzine
2015-10-26 20:40 ` Niklas Holsti
2015-10-27 7:48 ` comicfanzine
0 siblings, 2 replies; 4+ messages in thread
From: comicfanzine @ 2015-10-26 10:21 UTC (permalink / raw)
Can someone please post a simple code in which this function is used , i'm lost , thanks .
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io
2015-10-26 10:21 HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io comicfanzine
@ 2015-10-26 20:40 ` Niklas Holsti
2015-10-27 7:48 ` comicfanzine
1 sibling, 0 replies; 4+ messages in thread
From: Niklas Holsti @ 2015-10-26 20:40 UTC (permalink / raw)
On 15-10-26 12:21 , comicfanzine@gmail.com wrote:
> Can someone please post a simple code in which this function is used , i'm lost , thanks .
The following program can be run with or without command-line arguments.
If, and only if, there are command-line arguments, the program creates
and writes some text to a file called my_log_file.txt.
with Ada.Command_Line;
with Ada.Text_IO;
procedure Ex_Is_Open
is
Log_File : Ada.Text_IO.File_Type;
--
-- File for log output.
-- Created only if the program has command-line arguments.
procedure Log (Text : in String)
--
-- Log the Text, if the Log_File is open.
--
is
begin
if Ada.Text_IO.Is_Open (Log_File) then
Ada.Text_IO.Put_Line (Log_File, Text);
end if;
end Log;
begin -- Ex_Is_Open
Log ("This will not appear in the log.");
if Ada.Command_Line.Argument_Count > 0 then
Ada.Text_IO.Put_Line ("Creating log file my_log_file.txt.");
Ada.Text_IO.Create (
File => Log_File,
Name => "my_log_file.txt",
Mode => Ada.Text_IO.Out_File);
end if;
Log ("This will appear iff there are command-line arguments.");
if Ada.Text_IO.Is_Open (Log_File) then
-- We close the log.
-- Trying to Close the Log_File if it is not open
-- raises the exception Ada.Text_IO.Status_Error.
Ada.Text_IO.Close (Log_File);
end if;
Log ("This will not appear in the log.");
end Ex_Is_Open;
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io
2015-10-26 10:21 HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io comicfanzine
2015-10-26 20:40 ` Niklas Holsti
@ 2015-10-27 7:48 ` comicfanzine
2015-10-27 11:23 ` Simon Wright
1 sibling, 1 reply; 4+ messages in thread
From: comicfanzine @ 2015-10-27 7:48 UTC (permalink / raw)
Le lundi 26 octobre 2015 11:22:01 UTC+1, comicf...@gmail.com a écrit :
> Can someone please post a simple code in which this function is used , i'm lost , thanks .
Thanks Niklas Holsti ,
I understand but partially , can you explain me in details those lines please? i don't know what you mean by '''Log''' = is that kind of a comment line ? :
line 31 (procedure Ex_Is_Open) = Log ("This will not appear in the log.");
line 44 (procedure Ex_Is_Open) = Log ("This will appear iff there are command-line arguments.");
line 55 (procedure Ex_Is_Open) = Log ("This will not appear in the log.");
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io
2015-10-27 7:48 ` comicfanzine
@ 2015-10-27 11:23 ` Simon Wright
0 siblings, 0 replies; 4+ messages in thread
From: Simon Wright @ 2015-10-27 11:23 UTC (permalink / raw)
comicfanzine@gmail.com writes:
> Le lundi 26 octobre 2015 11:22:01 UTC+1, comicf...@gmail.com a écrit :
>> Can someone please post a simple code in which this function is used
> , i'm lost , thanks .
>
> Thanks Niklas Holsti ,
>
> I understand but partially , can you explain me in details those lines
> please? i don't know what you mean by '''Log''' = is that kind of a
> comment line ? :
>
> line 31 (procedure Ex_Is_Open) = Log ("This will not appear in the log.");
>
> line 44 (procedure Ex_Is_Open) = Log ("This will appear iff there are
> command-line arguments.");
>
> line 55 (procedure Ex_Is_Open) = Log ("This will not appear in the log.");
If you look at line 13 of Niklas's code you will see the declaration of
'procedure Log'.
If you know C, then - a procedure is like a void function.
But in any case, you need to work through a tutorial. There is a list of
tutorials at http://www.adaic.org/learn/materials/#tutorials - but you
may find AdaTutor (http://zhu-qy.blogspot.co.uk/2012/08/adatutor.html)
more useful.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-27 11:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-26 10:21 HELP | function Is_Open (File : File_Type) return Boolean; package ada.text_io comicfanzine
2015-10-26 20:40 ` Niklas Holsti
2015-10-27 7:48 ` comicfanzine
2015-10-27 11:23 ` Simon Wright
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox