comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: 4 beginner's questions on the PL Ada
Date: Sat, 10 Aug 2013 07:16:00 +0100
Date: 2013-08-10T07:16:00+01:00	[thread overview]
Message-ID: <ly7gfuqden.fsf@pushface.org> (raw)
In-Reply-To: 87mwoqbao2.fsf@VLAN-3434.student.uu.se

Emanuel Berg <embe8573@student.uu.se> writes:

> Anh Vo <anhvofrcaus@gmail.com> writes:
>
>> You can give/assign a name to a task the way you like by using
>> predefined package Ada.Task_Attributes. In this case you most
>> likely instantiate it with String subtype. Therefore, it is will
>> be completely portable.
>
> And (drumroll...) how would that look?

Well, it turns out to be more complicated than Ahn Vo said, because
Ada.Task_Attributes[1] has to be instantiated with a definite type (it
begins "type Attribute is private;") and String is indefinite.

So it might look like

with Ada.Strings.Bounded;
with Ada.Task_Attributes;
with Ada.Task_Identification;
with Ada.Text_IO; use Ada.Text_IO;
procedure Task_Naming is
   package Task_Name_Strings
   is new Ada.Strings.Bounded.Generic_Bounded_Length (Max => 64);
   package Task_Names
   is new Ada.Task_Attributes
     (Attribute => Task_Name_Strings.Bounded_String,
      Initial_Value => Task_Name_Strings.Null_Bounded_String);
   task Tsk is end Tsk;
   task body Tsk is
   begin
      delay 5.0;
   end Tsk;
begin
   Task_Names.Set_Value (T => Tsk'Identity,
                         Val => Task_Name_Strings.To_Bounded_String ("foo"));
   --  later ...
   Put_Line
     ("id is "
        & Task_Name_Strings.To_String (Task_Names.Value (Tsk'Identity)));
end Task_Naming;

Alternatively, you could say

   subtype Task_Name_String is String (1 .. 16);
   package Task_Names
   is new Ada.Task_Attributes
     (Attribute => Task_Name_String,
      Initial_Value => (others => ' '));

but then you'd have to say

   Task_Names.Set_Value (T => Tsk'Identity,
                         Val => ('f', 'o', 'o', others => ' '));

> You guys should do a field trip to gnu.emacs.help - there, we just
> post code all days! It is much better. Code speaks louder than
> words. It is very difficult to follow all this discussion on
> memory allocation etc., but the few times you posted code there
> wasn't a letter I didn't understand immediately.

We don't like to post code that doesn't work, and producing a working
example takes time. Also, we have an excellent on-line reference manual,
though it takes a special kind of person to want to read it at bed-time!

[1] http://www.adaic.org/resources/add_content/standards/12rm/html/RM-C-7-2.html


  reply	other threads:[~2013-08-10  6:16 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
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 [this message]
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