comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: discriminant questions
Date: Fri, 23 Sep 2011 12:57:40 +0200
Date: 2011-09-23T12:57:41+02:00	[thread overview]
Message-ID: <4e7c6625$0$6556$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <fsmyepvncyb2$.2ik4vw3vu74h.dlg@40tude.net>

On 23.09.11 09:59, Dmitry A. Kazakov wrote:

> Can I declare an iterator object constant? What is the meaning of its
> "constantness" when the container gets manipulated? See a huge language
> problem here? An iterator can be immutable only if the container is. How do
> I express such stuff in the language?

Well, have one more level of indirection, and one aspect (i.e., only
two more kludges ;-)  Not sure whether the aspect can be checked at
compile time, though, or to what extent.

Compiling: const.adb (source file time stamp: 2011-09-23 10:27:42)

     1. with Ada.Containers.Vectors;
     2.
     3. procedure Const is
     4.
     5.    type E is (Mon, Bin, Ter);
     6.    subtype P is Positive range 1 .. 100;
     7.
     8.    package Vec is new Ada.Containers.Vectors
     9.      (Element_Type => E,
    10.       Index_Type => P);
    11.
    12.    type Const_Vector is access constant Vec.Vector;
    13.    type Const_Cursor is new Vec.Cursor
    14.      with Invariant => Has_Element (Const_Cursor);
    15.
    16.    procedure Change (Element : in out E) is
    17.    begin
    18.       if Element = E'Last then
    19. 	 Element := E'First;
    20.       else
    21. 	 Element := E'Succ (Element);
    22.       end if;
    23.    end Change;
    24.
    25.    function Frozen (V : Vec.Vector) return Const_Vector is
    26.    begin
    27.       return V'Unchecked_Access;
    28.    end Frozen;
    29.
    30.    Container : Vec.Vector;
    31.    Position  : Vec.Cursor;
    32.    Const_Container : Const_Vector;
    33. begin
    34.    Container.Append(Mon);
    35.    Container.Append(Ter);
    36.    Position := Container.First;
    37.    Vec.Update_Element (Container,
    38. 		       Position,
    39. 		       Process => Change'Access);
    40.    Const_Container := Frozen (Container);
    41.    Vec.Update_Element (Const_Container.all,
                                               |
        >>> actual for "Container" must be a variable

    42. 		       Position,
    43. 		       Process => Change'Access);
    44.
    45. end Const;
    46.
    47.
    48.

 48 lines: 1 error
gnatmake: "const.adb" compilation error

Compilation exited abnormally with code 4 at Fri Sep 23 10:27:53



  reply	other threads:[~2011-09-23 11:01 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-17 16:30 discriminant questions ytomino
2011-09-17 17:19 ` Dmitry A. Kazakov
2011-09-17 17:46   ` ytomino
2011-09-17 19:41     ` Dmitry A. Kazakov
2011-09-17 22:55       ` ytomino
2011-09-18  8:50         ` Dmitry A. Kazakov
2011-09-18 10:54           ` ytomino
2011-09-18 11:35             ` Dmitry A. Kazakov
2011-09-18 12:41               ` ytomino
2011-09-18 13:17                 ` Dmitry A. Kazakov
2011-09-18 16:22                   ` ytomino
2011-09-18 16:32                   ` ytomino
2011-09-18 18:15                     ` Dmitry A. Kazakov
2011-09-18 23:44                       ` ytomino
2011-09-19  7:27                         ` Dmitry A. Kazakov
2011-09-18 14:43               ` Dmitry A. Kazakov
2011-09-18 16:46               ` Robert A Duff
2011-09-18 18:01                 ` Dmitry A. Kazakov
2011-09-18 19:20                   ` Maciej Sobczak
2011-09-19  7:39                     ` Dmitry A. Kazakov
2011-09-19 20:00                       ` Maciej Sobczak
2011-09-20  7:33                         ` Dmitry A. Kazakov
2011-09-20 15:45                           ` Maciej Sobczak
2011-09-20 16:48                             ` Dmitry A. Kazakov
2011-09-20 20:19                               ` Maciej Sobczak
2011-09-21  7:48                                 ` Dmitry A. Kazakov
2011-09-21 20:51                                   ` Maciej Sobczak
2011-09-22  8:07                                     ` Dmitry A. Kazakov
2011-09-22 20:57                                       ` Maciej Sobczak
2011-09-23  7:59                                         ` Dmitry A. Kazakov
2011-09-23 10:57                                           ` Georg Bauhaus [this message]
2011-09-23 22:30                                           ` Randy Brukardt
2011-09-23 22:50                                           ` Randy Brukardt
2011-09-24  6:46                                             ` Dmitry A. Kazakov
2011-09-26 22:48                                               ` Randy Brukardt
2011-09-27  8:10                                                 ` Dmitry A. Kazakov
2011-09-27 10:18                                                   ` Georg Bauhaus
2011-09-27 12:14                                                     ` Dmitry A. Kazakov
2011-09-27 15:11                                                       ` Georg Bauhaus
2011-09-27 15:38                                                         ` Dmitry A. Kazakov
2011-09-27 18:06                                                           ` Georg Bauhaus
2011-09-27 19:06                                                             ` Dmitry A. Kazakov
2011-09-29  0:01                                                               ` Georg Bauhaus
2011-09-29  8:26                                                                 ` Dmitry A. Kazakov
2011-09-30  1:24                                                                   ` Randy Brukardt
2011-09-30  8:10                                                                     ` Dmitry A. Kazakov
2011-09-30 10:07                                                                   ` Georg Bauhaus
2011-09-30 12:38                                                                     ` Dmitry A. Kazakov
2011-09-30 17:40                                                                       ` Georg Bauhaus
2011-09-30 18:55                                                                         ` Dmitry A. Kazakov
2011-09-23  9:23                                       ` Stephen Leake
2011-09-23  9:48                                         ` Dmitry A. Kazakov
2011-09-23 22:42                                           ` Randy Brukardt
2011-09-24  6:56                                             ` Dmitry A. Kazakov
2011-09-26 22:43                                               ` Randy Brukardt
2011-09-24 10:47                                             ` Stephen Leake
2011-09-24 12:54                                       ` Simon Wright
2011-09-24 14:46                                         ` Dmitry A. Kazakov
2011-09-24 16:21                                           ` Simon Wright
2011-09-24 16:43                                             ` Dmitry A. Kazakov
2011-09-22  2:52                                   ` Randy Brukardt
2011-09-22  8:11                                     ` Dmitry A. Kazakov
2011-09-20  0:01           ` Randy Brukardt
2011-09-20  7:38             ` Dmitry A. Kazakov
2011-09-20 11:11               ` AdaMagica
2011-09-20 12:09                 ` Dmitry A. Kazakov
2011-09-20 12:31                   ` AdaMagica
2011-09-20 12:57                     ` Dmitry A. Kazakov
2011-09-20 23:28                       ` ytomino
2011-09-21  5:03                         ` AdaMagica
2011-09-21  8:08                         ` Dmitry A. Kazakov
2011-09-21 10:03                           ` Georg Bauhaus
2011-09-21 10:29                             ` Dmitry A. Kazakov
2011-09-22  3:21                           ` Randy Brukardt
2011-09-22  3:05                   ` Randy Brukardt
2011-09-19 23:35         ` Randy Brukardt
2011-09-20 21:39           ` ytomino
2011-09-22  3:32             ` Randy Brukardt
2011-09-18 16:32 ` ytomino
2011-09-19 14:46   ` ytomino
2011-09-19 15:14     ` Dmitry A. Kazakov
2011-09-19 17:49       ` ytomino
2011-09-20  7:29         ` Georg Bauhaus
2011-09-20 19:50           ` ytomino
2011-09-20  8:08         ` Dmitry A. Kazakov
2011-09-20 18:47           ` ytomino
2011-09-21  8:16             ` Dmitry A. Kazakov
2011-09-21  9:55               ` ytomino
2011-09-22  3:26                 ` Randy Brukardt
replies disabled

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