comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@aol.com>
Subject: Re: 4 beginner's questions on the PL Ada
Date: Fri, 9 Aug 2013 10:09:58 -0700 (PDT)
Date: 2013-08-09T10:09:58-07:00	[thread overview]
Message-ID: <03ea570b-e45f-4694-ab9b-3413c4770379@googlegroups.com> (raw)
In-Reply-To: <87ob96ajv6.fsf@VLAN-3434.student.uu.se>

On Friday, August 9, 2013 9:50:53 AM UTC-7, Emanuel Berg wrote:
> 1. How do you make a constant in Ada? Can I make one that is
> computed, for example an integer, set to Milliseconds(something)?

   Some_Constant : constant integer := <expression>.  The expression can be any expression that can be computed.

 
> 2. How do you get options from the CL? I.e., how do you do the C 
> argv in Ada?

Ada.Command_Line.  http://www.ada-auth.org/standards/12rm/html/RM-A-15.html

 
> 3. Is it possible to get the task *name* (from the code) into a 
> string, programatically? That way, a generic procedure could be
> used to communicate from tasks, with Put_Line, and without having
> to hard code the task name every time.

No, not really.  One thing to keep in mind is that Ada has task *types*, so that you can declare a task type and then start any number of tasks of that type.  And the tasks don't have to be associated with variables; you can start an array of tasks:

   type Task_Array is array (1 .. 10) of Task_Type;
   T : Task_Array;

will start 10 tasks, and they won't really have names.  Well, I guess you can call them T(1), T(2), ...  But tasks can also be record components, and you can have accesses to tasks, so there really isn't a concept of a "name" for a task.  So if you want to give tasks a name, you'll have to do this in the program.


> 4. How do you exit Ada altogether? For example, if there are 3 
> tasks, and one solves the problem, how can I terminate the whole
> application at once? (Rather than sending messages to all the
> tasks, "OK, we're done looking!")

I don't recommend having one task kill the entire program.  Ada allows you to define types that have finalization procedures associated with them (e.g. for a file, you might want a finalization procedure that makes sure any remaining data is flushed to the file).  Ada makes sure that when a procedure or task is exited, anything that needs to be finalized will be finalized.  Performing an operation that just exits the program suddenly will subvert that.  There's an "abort" statement to allow one task to terminate other tasks; that *does* ensure that finalization takes place.  But overall, I think it's better to do things cleanly; one way is to send a message to the other tasks with entry calls, but you can also create a variable (or a protected object) that's accessible to all tasks that they can check at certain points to see if they can quit.

                               -- Adam

  reply	other threads:[~2013-08-09 17:09 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 16:50 4 beginner's questions on the PL Ada Emanuel Berg
2013-08-09 17:09 ` Adam Beneschan [this message]
2013-08-09 17:16   ` Emanuel Berg
2013-08-09 17:46     ` Alan Jump
2013-08-09 18:10       ` Emanuel Berg
2013-08-09 19:01   ` Randy Brukardt
2013-08-09 21:38     ` Emanuel Berg
2013-08-09 22:00       ` Jeffrey Carter
2013-08-09 22:16         ` Emanuel Berg
2013-08-10  0:39           ` Anh Vo
2013-08-10  1:24             ` Emanuel Berg
2013-08-10  6:16               ` Simon Wright
2013-08-10 12:13                 ` Emanuel Berg
2013-08-10 17:12               ` Mike H
2013-08-10 17:53                 ` Emanuel Berg
2013-08-10 19:50                   ` Dennis Lee Bieber
2013-08-10 22:23                     ` Emanuel Berg
2013-08-11  7:12                       ` Georg Bauhaus
2013-08-11 12:44                         ` Emanuel Berg
2013-08-11 21:12                           ` Bill Findlay
2013-08-11 21:22                             ` Emanuel Berg
2013-08-12 17:39               ` Anh Vo
2013-08-12 18:15                 ` Anh Vo
2013-08-12 19:57                 ` Simon Wright
2013-08-12 20:13                   ` Anh Vo
2013-08-10  0:52           ` Jeffrey Carter
2013-08-12 19:47         ` Randy Brukardt
2013-08-09 22:08       ` Robert A Duff
2013-08-09 22:23         ` Emanuel Berg
2013-08-09 22:36           ` Robert A Duff
2013-08-09 22:42             ` Emanuel Berg
2013-08-09 23:48               ` Robert A Duff
2013-08-09 23:50                 ` Emanuel Berg
2013-08-09 23:56                 ` Emanuel Berg
2013-08-10  0:44                 ` Jeffrey Carter
2013-08-10  0:51                   ` Robert A Duff
2013-08-09 22:47             ` Alan Jump
2013-08-09 23:33               ` Adam Beneschan
2013-08-09 23:43                 ` Alan Jump
2013-08-10  0:19                   ` Robert A Duff
2013-08-10  0:52                   ` Jeffrey Carter
2013-08-10  0:48                 ` Robert A Duff
2013-08-09 23:40               ` Robert A Duff
2013-08-09 23:25       ` Dennis Lee Bieber
2013-08-09 18:29 ` Jeffrey Carter
2013-08-09 18:51   ` Adam Beneschan
2013-08-09 19:05     ` Jeffrey Carter
2013-08-09 18:35 ` Simon Wright
2013-08-09 23:21 ` Dennis Lee Bieber
2013-08-09 23:48   ` Emanuel Berg
2013-08-10  2:45     ` Dennis Lee Bieber
2013-08-10  3:33       ` Emanuel Berg
2013-08-10 14:57         ` Shark8
2013-08-10 17:43           ` Emanuel Berg
2013-08-10 17:55             ` Emanuel Berg
2013-08-10 23:15             ` Simon Clubley
2013-08-11 12:16               ` Emanuel Berg
2013-08-12 18:07               ` Adam Beneschan
2013-08-11  0:34             ` Shark8
2013-08-11 12:42               ` Emanuel Berg
2013-08-11 13:24                 ` Peter C. Chapin
2013-08-11 13:37                   ` Emanuel Berg
2013-08-11 15:15                   ` Mike H
2013-08-12 17:56           ` Adam Beneschan
2013-08-10  6:03       ` Jeffrey Carter
2013-08-12 17:17         ` Eryndlia Mavourneen
2013-08-12 17:27           ` Jeffrey Carter
2013-08-10 12:31 ` Emanuel Berg
2013-08-10 12:37   ` Emanuel Berg
2013-08-10 12:52     ` Emanuel Berg
replies disabled

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