comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: Generic Package
Date: Tue, 01 May 2007 15:42:21 +0200
Date: 2007-05-01T15:42:22+02:00	[thread overview]
Message-ID: <1178026941.16837.88.camel@localhost.localdomain> (raw)
In-Reply-To: <yrtifdx6n145$.fizmsut5omi6$.dlg@40tude.net>

On Tue, 2007-05-01 at 12:19 +0200, Dmitry A. Kazakov wrote:
> On Tue, 01 May 2007 11:02:22 +0200, Georg Bauhaus wrote:
> 
> > On Mon, 2007-04-30 at 22:04 +0200, Dmitry A. Kazakov wrote:
> >> It was that if foreach were a primitive operation
> >> defined on an unordered set, then its contract could not be stated.
> > 
> > Every specific Set object (collection of elements) inside a computer has
> > a memory layout.
> 
> So the memory layout is a part of the contract?

Yes, in the sense that the specifics of memory layout and such are
unknown and irrelevant to the client; in particular, no order needs
to be specified. However, it is then known that the elements of sets
in a computer have said properties. These properties will assign
meaning to the phrase
 "Procedure Foreach calls procedure P once for each element of S"
or, put differently but still with just logical references to
implementation details, "For each node of the set S, the node will
be used as the actual argument of P when P is invoked; this is
done once for each node of S in an unspecified order."
 There isn't much a client (programmer) needs to know about nodes.
He or she isn't concerned with implementation details.
But the abstract notions of what is implemented provide enough
formal information so that the operation of Foreach can be
described formally. (Just not in terms of its own inner workings
as a postcondition stating foreach in terms of foreach. So what?)

As a consequence of this formal description, ("nodes", "called once",
"each") I can call Foreach passing a procedure Add_One that increments
a count variable when called. Provided there is a query function
Length of Set (as is typically the case), then (remove quantifiers
if more apt)

 function Unnamed(S: Set) return Count_Type;
 -- post: (∀s) s in Set [ s.Length = Result ]

 function Unnamed(S: Set) return Count_Type is
    count_var: Count_Type;
    procedure Add_One(C: Cursor) is
    begin
       count_var := count_var + 1;
    end;
 begin
    count_var := 0;
    Foreach(S, Add_One'access);
    -- Claim (∀s) s in Set [ s.Length = count_var ]

    -- Proof. Foreach calls Add_One exactly once for each node
    -- in s. Add_One unconditionally increments Count_Var by 1.
    -- No other operation changes the value of Count_Var.
    -- Hence, Count_Var (initially zero) is incremented by 1 for
    -- each node in s, so Foreach counts the elements of s. ∎

    pragma assert(Length(S) = count_var);
    return count_var;
 end;

If there is no Length defined for Set, the above is still enough,
to me at least, to show that this computes the number of elements
in a Set using a computer representation even when there is no known
order of elements and without knowledge of the actual implementation.

I think it is possible to add even more contract clauses almost
like the ones you have mentioned:

function First(S: Set) return Cursor;
  -- post: let (Result then t0) = (First(S) then Clock),
  --           (Result' then t) = (First(S) then Clock) in
  --         (∀t) t > t0 [ Result /= Result' ]

As you can see, there is some order again but I don't have to know
the order. (Finding a first book (and then the next book) is the
job of the librarian, not mine.)



> >> To be able to pick a random member <=>
> >> to have an order.
> > 
> > Can you determine whether one of your sets is empty?
> 
> Sure. I can compare an empty set with the given set. This does not require
> picking elements.

Uhm, not require the client to pick or the implementation to pick?
When two sets A and B are equal iff the same elements
belong to both A and B, won't you need at least references to the
elements for "=" to be called for the elements?






  reply	other threads:[~2007-05-01 13:42 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-25 22:15 Generic Package andrew.carroll
2007-04-26  0:07 ` Jeffrey R. Carter
2007-04-26  7:46   ` Markus E Leypold
2007-04-26  6:02 ` Martin Krischik
2007-04-26  7:57 ` Dmitry A. Kazakov
2007-04-26 15:31 ` andrew.carroll
2007-04-26 16:07   ` Georg Bauhaus
2007-04-26 19:40     ` andrew.carroll
2007-04-26 20:01       ` Georg Bauhaus
2007-04-26 18:54   ` Dmitry A. Kazakov
2007-04-26 21:52     ` Simon Wright
2007-04-27  9:00       ` Dmitry A. Kazakov
2007-04-27 11:11         ` Georg Bauhaus
2007-04-27 12:06           ` Dmitry A. Kazakov
2007-04-27 12:52             ` Markus E Leypold
2007-04-27 14:10             ` Georg Bauhaus
2007-04-27 14:16               ` Dmitry A. Kazakov
2007-04-27 21:44                 ` Georg Bauhaus
2007-04-28  7:38                   ` Dmitry A. Kazakov
2007-04-28 17:50                     ` Simon Wright
2007-04-28 21:04                     ` Ray Blaak
2007-04-29 16:33                       ` Markus E Leypold
2007-04-27 19:44             ` Simon Wright
2007-04-27 20:34               ` Dmitry A. Kazakov
2007-04-27 21:16                 ` Simon Wright
2007-04-28  7:36                   ` Dmitry A. Kazakov
2007-04-27 11:43         ` Markus E Leypold
2007-04-28 17:35           ` Dmitry A. Kazakov
2007-04-28 23:06             ` Georg Bauhaus
2007-04-29  8:19               ` Dmitry A. Kazakov
2007-04-29 15:10                 ` (see below)
2007-04-29 17:48                   ` Dmitry A. Kazakov
2007-04-29 22:36                     ` (see below)
2007-04-30  6:58                       ` Dmitry A. Kazakov
2007-04-30  9:59                         ` Markus E Leypold
2007-04-30 10:01                         ` Markus E Leypold
2007-04-30 10:36                         ` Georg Bauhaus
2007-04-30 10:40                           ` Georg Bauhaus
2007-04-30 12:14                           ` Dmitry A. Kazakov
2007-04-30 14:57                         ` (see below)
2007-04-30 10:30                 ` Georg Bauhaus
2007-04-30 12:16                   ` Dmitry A. Kazakov
2007-04-30 14:48                     ` Georg Bauhaus
2007-04-30 16:29                       ` Dmitry A. Kazakov
2007-04-30 17:24                         ` Georg Bauhaus
2007-04-30 18:54                           ` Dmitry A. Kazakov
2007-04-30 19:29                         ` Simon Wright
2007-04-30 20:04                           ` Dmitry A. Kazakov
2007-05-01  0:11                             ` Markus E Leypold
2007-05-01  9:02                             ` Georg Bauhaus
2007-05-01 10:19                               ` Dmitry A. Kazakov
2007-05-01 13:42                                 ` Georg Bauhaus [this message]
2007-05-01 17:16                                   ` Dmitry A. Kazakov
2007-05-01 19:14                                     ` Randy Brukardt
2007-05-01 20:14                                       ` Dmitry A. Kazakov
2007-05-02  7:52                                         ` Markus E Leypold
2007-05-02  8:06                                       ` Markus E Leypold
2007-05-03  0:37                                         ` Randy Brukardt
2007-05-03  8:36                                           ` Markus E Leypold
2007-05-03 23:16                                             ` Randy Brukardt
2007-05-04  0:15                                               ` Markus E Leypold
2007-05-01 21:41                                     ` Georg Bauhaus
2007-05-02  6:57                                       ` Ray Blaak
2007-05-02  8:22                                         ` Markus E Leypold
2007-05-02  8:07                                       ` Markus E Leypold
2007-05-02 10:29                                       ` Dmitry A. Kazakov
2007-05-02 11:48                                         ` Georg Bauhaus
2007-05-02 11:50                                           ` Georg Bauhaus
2007-05-02 13:12                                           ` Dmitry A. Kazakov
2007-05-02 14:21                                             ` Markus E Leypold
2007-05-03 18:27                                             ` Georg Bauhaus
2007-05-03 19:07                                               ` Dmitry A. Kazakov
2007-05-03 19:49                                                 ` Markus E Leypold
2007-04-29 16:26             ` Markus E Leypold
2007-04-26 21:50   ` Simon Wright
2007-04-27  4:45   ` Jeffrey R. Carter
2007-04-27  7:45     ` Martin Krischik
2007-04-27 22:54       ` Georg Bauhaus
2007-04-30 20:13         ` Matthew Heaney
2007-04-26 20:48 ` andrew.carroll
  -- strict thread matches above, loose matches on Subject: below --
2003-12-02 23:15 Mr. J.
2003-12-03  9:31 ` Dmitry A. Kazakov
2003-12-02 23:13 generic package Ratson Janiv
2003-12-03 17:39 ` Stephen Leake
replies disabled

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