comp.lang.ada
 help / color / mirror / Atom feed
From: Markus E Leypold <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
Subject: Re: Generic Package
Date: Tue, 01 May 2007 02:11:53 +0200
Date: 2007-05-01T02:11:53+02:00	[thread overview]
Message-ID: <gzmz0pwgfq.fsf@hod.lan.m-e-leypold.de> (raw)
In-Reply-To: 1ieq3io2d6nnq$.13818v3y35gnr.dlg@40tude.net


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Mon, 30 Apr 2007 20:29:22 +0100, Simon Wright wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>> On Mon, 30 Apr 2007 16:48:53 +0200, Georg Bauhaus wrote:
>> 
>>>> "The foreach procedure operates as if the following body
>>>> were written
>>>> 
>>>>     procedure foreach(S: Set) is
>>>>        C: Cursor;
>>>>     begin
>>>>        C := first(S);
>>>
>>> You forgot that first is not defined on Set, which is not
>>> well-ordered and thus does not have visible implementations of
>>> first, last, next, prev etc in its interface. It has Length, =, /=,
>>>:=, and, or, xor, /, Empty, in, not in. [*]
>> 
>> First is not *publicly* defined on Set but this is *implementation*,
>> for Pete's sake! It's likely to be hard to implement iteration/foreach
>> efficiently without private knowledge
>
> You missed the point. It was that if foreach were a primitive operation

No, you're missing the point.

You've asserted that one "cannot iterate over relational tables
because they are not ordered". Then you shifted the discussion to sets
as an example -- in this case I'll permit it. So we're now talking
about wether one can iterate over sets.

Now, we are talking about _implementation_. And wether one can
implement an iteration mechanism for sets (not necessarily in terms of
the set primitive operations). 

I already could stop talking here, since iteration over set data
structures has been implemented often enough. But just to complete the
argument:

We call a set/container implementation unordered, if the user is not
required to provide an order function when the instantiating (either
an object or a generic). That doesn't preclude an implementation from
either using an internal, implementation dependent order to implement
iteration or just use the following method:

 1) for First() find some arbitrary element in the container/set. 
    Mark it as already visited in the iterator state and return it.

 2) for Next() find some other element in the container that hasn't
    ben visited yet.

    Mark it as already visited in the iterator state and return it.

That requires that there is an internal way for the implementation to
walk over all the the elements in the container. Nonetheless -- the
thing implemented is still a set (in any useful interpretation), even
if it has some ad-hoc ordering internally. What makes it a set is,
that it exposes the operations
  
 - Empty  -- construct an empty set
 - Add    -- add an element
 - Remove -- remove an alement
 - Is_In  -- Test wether element is in Set.

It doesn't magically become a non-set if it also exposes iteration operations

 - Start    -- Create an Iterator/Cursor.
 - Element  -- Extract Element from Cursor
 - Next     -- Set Cursor to next Element

Note that there is no implementation exposed.

Some example: A simple _implementation_ for a finite set would be a
linked list.  Interesting enough, there is a mechanism to walk through
all elements in the set, but that doesn't impose an order in the sense
the word is used in "ordered set". Because the data type "ordered set"
is defined as a base set B and a relation f, so that f has certain
properties and any value of the data type is a subset of B. The
sequence in which a given set S \subset_of B is visited by walking the
linked list: s1, s2, s3 ..., doesn't produce a relation on all of B.

Got the difference?

I'm a bit suprised you don't know this, since you said you have been
studying mathematics.

> defined on an unordered set, then its contract could not be stated. 

And that is nonsense too. Shall we?

(A) We define cursors (abstractly) as thingies tha

 # The following operations/functions have to be implemented
 # Every function w/o a precondition has to be total.

 Element: c:Cursor => e:Element
    post: e \in Set(c)            # see below

 # The following are only helper functions for the functional spec.
 # They describe the cursor state for purposes of the specification.

 Set    : c:Cursor => s:Set

 Visited: c:Cursor => s:Set
    post: Element(c) \in s AND s \subset_of Set(c) 

 # Note: The post condition of Visited just describes the limits
 # within which the state a Cursor which has been "attached" to a
 # given set Set(c) can change.


(B) We define iteration as operations on cursors

 First: s:Set => c:Cursor

    post: Element(c) \in s AND Visited(c) = { Element(c) } AND Set(c) = s 

    # Note: Any choice of Element(c) from s will satisfy the requirement. You might even
    # randomly select an element from s. Set(c) is necessary to memorize the set we're
    # iterating over (this is in the nature of a functional spec).

 Next:  c:Cursor => c:'Cursor
    
    pre:  Set(c) \without Visited(c) is not empty
    post:     Set(c) = Set(c')                # consistency, continues iteration over Set(c)
          AND Element(c') \in Set(c) 
          AND Element(c') \not\in Visited(c)                 # pick an element not yet visited
          AND Visited(c') = Visited(c) \union { Element(c')  # memorize "new" Element as visited

    # Note: Again the element picked is arbitrary, but must not have been seen before.


So -- where did I use an order function (which would have to be valid
for every s \in Set)? Do you deny that this functional specfication
describes a contract for cursors to iterate over sets?

> I answered to this in a subthread. To be able to pick a random member <=>
> to have an order.

No. Your definition of order (specifically an ordered data type) lacks precision.

Regards -- Markus



  reply	other threads:[~2007-05-01  0:11 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 [this message]
2007-05-01  9:02                             ` Georg Bauhaus
2007-05-01 10:19                               ` Dmitry A. Kazakov
2007-05-01 13:42                                 ` Georg Bauhaus
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