comp.lang.ada
 help / color / mirror / Atom feed
* Please help a newbie with Booch/Ada.
@ 1998-08-20  0:00 Lengyel Sandor
  1998-08-21  0:00 ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Lengyel Sandor @ 1998-08-20  0:00 UTC (permalink / raw)


I am fooling around with the Booch components, since I think
"Collections" are very usefull.

I tried out Single_List. It works fine for a data = Character.

I tried to make it work for string.

First I generated a string_references.ads as follows:

   PACKAGE String_References IS
      TYPE String_ptr IS ACCESS ALL String;
      TYPE Const_String_Ptr IS ACCESS CONSTANT String;
   END String_References;


Then I created a root_string_container.ads as:

   with Bc.Containers;
   with String_References;
   package Root_String_Container is new Bc.Containers
      (String,String_References.String_ptr);


(Coping the format of root_container.ads. :-) )

When I run a semanric check on this later code, I get the following
message.

root_string_container.ads:4:08: actual for "Item" must be a definite
subtype.


?? What does it mean !definite! subtype.
Why Character fulfills this requirement but String does not.
Where in the literature can I find explanations for these messages. The
expression "definite subtype" is not in my Ada book. (Subtype of course
is.)

How can one make Booch work for Strings?

Thanks.

-- 
 Lengyel Sándor

Hass, alkoss, gyarapits,
S a haza fényre derül. (Kölcsey)




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please help a newbie with Booch/Ada.
  1998-08-20  0:00 Please help a newbie with Booch/Ada Lengyel Sandor
@ 1998-08-21  0:00 ` Stephen Leake
  1998-08-21  0:00   ` Lengyel Sandor
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Stephen Leake @ 1998-08-21  0:00 UTC (permalink / raw)


Lengyel Sandor <hunnia@pacbell.net> writes:

> I am fooling around with the Booch components, since I think
> "Collections" are very usefull.

good idea.

>    PACKAGE String_References IS
>       TYPE String_ptr IS ACCESS ALL String;
>       TYPE Const_String_Ptr IS ACCESS CONSTANT String;
>    END String_References;
> 
> 
> Then I created a root_string_container.ads as:
> 
>    with Bc.Containers;
>    with String_References;
>    package Root_String_Container is new Bc.Containers
>       (String,String_References.String_ptr);
> 
> 
> (Coping the format of root_container.ads. :-) )
> 
> When I run a semanric check on this later code, I get the following
> message.
> 
> root_string_container.ads:4:08: actual for "Item" must be a definite
> subtype.

See RM 3.3 (23). Basically, an indefinite type is any unconstrained
type (in this case, String is an unconstrained array). A definite type
is a constrained type.

The problem is that the Ada 95 Booch components are modeled after the
C++ Booch components. Since there is no such thing as an "indefinite
type" in C++, the Ada 95 Booch components restrict you to definite
types. This is one of the advantages of Ada 95 over C++; you can give
more information about the type. On the other hand, a careless library
author can shoot you down.

As a work around, you can use Ada.Strings.Unbounded.Unbounded_String
instead of String.

Better would be to fix the Ada 95 Booch components to allow indefinite
types. Find the declaration of Bc.Containers, and add "(<>)" as a
discriminant to the object type. Be aware this might break lots of
stuff; I haven't tried it.

-- Stephe




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please help a newbie with Booch/Ada.
  1998-08-21  0:00 ` Stephen Leake
@ 1998-08-21  0:00   ` Lengyel Sandor
  1998-08-27  0:00   ` Simon Wright
  1998-08-30  0:00   ` Matthew Heaney
  2 siblings, 0 replies; 6+ messages in thread
From: Lengyel Sandor @ 1998-08-21  0:00 UTC (permalink / raw)


Stephen Leake wrote:
> 
> Lengyel Sandor <hunnia@pacbell.net> writes:
> 
> > I am fooling around with the Booch components, since I think
> > "Collections" are very usefull.
> 
> good idea.
> 
> >    PACKAGE String_References IS
> >       TYPE String_ptr IS ACCESS ALL String;
> >       TYPE Const_String_Ptr IS ACCESS CONSTANT String;
> >    END String_References;
> >
> >
> > Then I created a root_string_container.ads as:
> >
> >    with Bc.Containers;
> >    with String_References;
> >    package Root_String_Container is new Bc.Containers
> >       (String,String_References.String_ptr);
> >
> >
> > (Coping the format of root_container.ads. :-) )
> >
> > When I run a semanric check on this later code, I get the following
> > message.
> >
> > root_string_container.ads:4:08: actual for "Item" must be a definite
> > subtype.
> 
> See RM 3.3 (23). Basically, an indefinite type is any unconstrained
> type (in this case, String is an unconstrained array). A definite type
> is a constrained type.
> 
> The problem is that the Ada 95 Booch components are modeled after the
> C++ Booch components. Since there is no such thing as an "indefinite
> type" in C++, the Ada 95 Booch components restrict you to definite
> types. This is one of the advantages of Ada 95 over C++; you can give
> more information about the type. On the other hand, a careless library
> author can shoot you down.
> 
> As a work around, you can use Ada.Strings.Unbounded.Unbounded_String
> instead of String.
> 
> Better would be to fix the Ada 95 Booch components to allow indefinite
> types. Find the declaration of Bc.Containers, and add "(<>)" as a
> discriminant to the object type. Be aware this might break lots of
> stuff; I haven't tried it.
> 
> -- Stephe

At work I tried the Bounded_String approach, (before I read this
letter), and I got it working.
I am not impressed with the booch components so far. I had to create
quite a few new packages.
Now that it is done, it is easy to use. 
  I don't know much about Ada, but feel that redoing the object types as
you suggested, should have been the way to go. There should be a
collection library more general and easier to use. Is there one?
Also the documentation for the Booch components is almost non existent.
Maybe it is enough for an expert, but I spent 1 day to get it working
for Strings.

Sandor



-- 
 Lengyel Sándor

Hass, alkoss, gyarapits,
S a haza fényre derül. (Kölcsey)




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please help a newbie with Booch/Ada.
  1998-08-21  0:00 ` Stephen Leake
  1998-08-21  0:00   ` Lengyel Sandor
@ 1998-08-27  0:00   ` Simon Wright
  1998-08-30  0:00   ` Matthew Heaney
  2 siblings, 0 replies; 6+ messages in thread
From: Simon Wright @ 1998-08-27  0:00 UTC (permalink / raw)


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> Lengyel Sandor <hunnia@pacbell.net> writes:
> 
> > I am fooling around with the Booch components, since I think
> > "Collections" are very usefull.
> 
> good idea.
> 
> >    PACKAGE String_References IS
> >       TYPE String_ptr IS ACCESS ALL String;
> >       TYPE Const_String_Ptr IS ACCESS CONSTANT String;
> >    END String_References;
> > 
> > 
> > Then I created a root_string_container.ads as:
> > 
> >    with Bc.Containers;
> >    with String_References;
> >    package Root_String_Container is new Bc.Containers
> >       (String,String_References.String_ptr);
> > 
> > 
> > (Coping the format of root_container.ads. :-) )
> > 
> > When I run a semanric check on this later code, I get the following
> > message.
> > 
> > root_string_container.ads:4:08: actual for "Item" must be a definite
> > subtype.
> 
> See RM 3.3 (23). Basically, an indefinite type is any unconstrained
> type (in this case, String is an unconstrained array). A definite type
> is a constrained type.
> 
> The problem is that the Ada 95 Booch components are modeled after the
> C++ Booch components. Since there is no such thing as an "indefinite
> type" in C++, the Ada 95 Booch components restrict you to definite
> types. This is one of the advantages of Ada 95 over C++; you can give
> more information about the type. On the other hand, a careless library
> author can shoot you down.

:-)

> As a work around, you can use Ada.Strings.Unbounded.Unbounded_String
> instead of String.

This was my recommendation to another user.

> Better would be to fix the Ada 95 Booch components to allow indefinite
> types. Find the declaration of Bc.Containers, and add "(<>)" as a
> discriminant to the object type. Be aware this might break lots of
> stuff; I haven't tried it.

This is a possibility, but since the components require the generic
type Item to be copyable I don't think it will work?

A fix for Lengyel would be to declare

  type String_ptr_ptr ias access String_ptr;

and instantiate with

  package Root_String_Container is new Bc.Containers
     (String_References.String_ptr, String_References.String_ptr_ptr);

I have in mind that this instantiation with 2 pointers is confusing
and tedious, as far as I can see at the moment it's there to support
iterators where the iterating procedure can modify the item;

  function Current_Item (Obj : Iterator) return Item_Ptr;

and

  generic
    with procedure Apply (Elem_Ref : in Item_Ptr; OK : out Boolean);
  function Modify (Obj : access Passive_Iterator) return Boolean;

I think both of these would be better Ada if they used in out
parameters, eg

  generic
    with procedure Apply (Elem : in out Item; OK : out Boolean);
  function Modify (Obj : access Passive_Iterator) return Boolean;




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please help a newbie with Booch/Ada.
  1998-08-21  0:00 ` Stephen Leake
  1998-08-21  0:00   ` Lengyel Sandor
  1998-08-27  0:00   ` Simon Wright
@ 1998-08-30  0:00   ` Matthew Heaney
  1998-09-01  0:00     ` Brian Rogoff
  2 siblings, 1 reply; 6+ messages in thread
From: Matthew Heaney @ 1998-08-30  0:00 UTC (permalink / raw)


Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:

> Better would be to fix the Ada 95 Booch components to allow indefinite
> types. Find the declaration of Bc.Containers, and add "(<>)" as a
> discriminant to the object type. Be aware this might break lots of
> stuff; I haven't tried it.

The Booch components aren't broken.  Just build collections of
indefinate subtypes on top of collections of definate subtypes.  This
layer is sort of an adapter pattern, to convert between a handle
(definate, implemented as a pointer) and the item itself (indefinate).

It was suggested that one instantiate the (definate item) stack with
Ada.Strings.Unbounded.  However, this would put onus on the user of the
collection to change a string into an unbounded string, then put that
into the collection, and do the reverse when retrieving an item.

A hipper approach is for the client to write a stack adapter, and let
the conversion between String and Unbounded_String be hidden as an
implementation detail.  Something like:

package String_Stacks is

   type String_Stack is private;

   procedure Push (Source : in String; On : in out String_Stack);

   function Get_Top (Stack : String_Stack) return String;
...
private

   package Unbounded_String_Stacks is 
      new BC.Stacks.Unbounded (Ada.Strings.Unbounded.Unbounded_String);

   use Unbounded_String_Stacks;

   type String_Stack is
      record
         Rep : Unbounded_Stack;
      end record;

end String_Stacks;


package body String_Stacks is 

   procedure Push (Source : in String; On : in out String_Stack) is

      Stack : Unbounded_Stack renames On.Rep;
   begin
      Push (To_Unbounded_String (Source), On => Stack);
   end;

   function Get_Top (Stack : String_Stack) return String is
   begin
      return To_String (Get_Top (Stack.Rep));
   end;

...
end String_Stacks;


Now the client can use the stack in a natural way:

  Push ("Ada, je t'aime.", On => Stack);

declare
   Top : String renames Get_Top (Stack);
begin
...


A component library can't be all things to all people.  Better is to
provide a small-ish set of primitives from which clients can compose
their own custom-built abstractions.

Making all the containers take indefinate subtypes would be the worst of
all possible decisions, because that would mean _every_ instantiation
would use heap, even those clients that have definate subtypes.

The Booch Components (nor any lib) shouldn't get in the business of
deciding for the client how the memory manage indefinate subtypes.
Provide a container for definate subtypes, and let the client build an
adapter on top of that.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Please help a newbie with Booch/Ada.
  1998-08-30  0:00   ` Matthew Heaney
@ 1998-09-01  0:00     ` Brian Rogoff
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Rogoff @ 1998-09-01  0:00 UTC (permalink / raw)


On Sun, 30 Aug 1998, Matthew Heaney wrote:
> Stephen Leake <Stephen.Leake@gsfc.nasa.gov> writes:
> 
> > Better would be to fix the Ada 95 Booch components to allow indefinite
> > types. Find the declaration of Bc.Containers, and add "(<>)" as a
> > discriminant to the object type. Be aware this might break lots of
> > stuff; I haven't tried it.
> 
> ... snip ... 
> 
> A component library can't be all things to all people.  Better is to
> provide a small-ish set of primitives from which clients can compose
> their own custom-built abstractions.
> 
> Making all the containers take indefinate subtypes would be the worst of
> all possible decisions, because that would mean _every_ instantiation
> would use heap, even those clients that have definate subtypes.

I agree, but let me note that when a library provides a set of reusable 
generic signatures, I think its a good idea that the parameters to those
signatures be as general as possible, which may mean generic formal 
indefinite limited private types (what a mouthful!).

-- Brian





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-09-01  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-08-20  0:00 Please help a newbie with Booch/Ada Lengyel Sandor
1998-08-21  0:00 ` Stephen Leake
1998-08-21  0:00   ` Lengyel Sandor
1998-08-27  0:00   ` Simon Wright
1998-08-30  0:00   ` Matthew Heaney
1998-09-01  0:00     ` Brian Rogoff

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