comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: project euler 26
  2023-09-07  9:02  4%                               ` Dmitry A. Kazakov
@ 2023-09-08  1:32  0%                                 ` Ben Bacarisse
  0 siblings, 0 replies; 53+ results
From: Ben Bacarisse @ 2023-09-08  1:32 UTC (permalink / raw)


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

> On 2023-09-07 01:32, Ben Bacarisse wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> 
>>> On 2023-09-06 17:16, Ben Bacarisse wrote:
>>>
>>>> I am curious to know how reusable this is.  Can the packages be
>>>> instantiated in such a way that the argument ranges over the elements
>>>> of, say, and Ordered_Map?
>>>
>>> Sure:
>>>
>>>     with Ada.Containers.Ordered_Maps;
>>>
>>>     package Integer_Maps is
>>>        new Ada.Containers.Ordered_Maps (Integer, Integer);
>>>     use Integer_Maps;
>>>     package Cursor_Arguments is new Generic_Arguments (Cursor);
>> Ah!  So the arguments correspond to the "with" functions in the order
>> listed, and, since Cursor already has Next, there no need to specify
>> anything.
>
> Yes, because the formal argument is
>
>    with function Next (Value : Argument_Type)
>       return Argument_Type is <>;
>
> If it were
>
>    with function Next (Value : Argument_Type)
>       return Argument_Type;
>
> You would have to specify the actual. The part "is <>" tells to match a
> visible function Next.

Thanks.  I remember that now.  Given Ada's preference for words, it's a
mysterious choice.

>> There are a couple of details that prevent your Maximum_At function from
>> working properly in this case though.  First, we can't have an empty
>> map, because X.Last can't be compared with X.First when either is
>> No_Element, so the test for Right < Left fails before the desired error
>> can be raised.
>
> Yes, cursors is bad idea, in the end they all are pointers. No_Element is
> an equivalent of null which shows.
>
> However Maximum_At will propagate Constraint_Error if either of the bounds
> is No_Element. So the implementation would work.

Sure, but ideally we want the error we decided on for this situation.
Since the intent is to be generic, it's a shame to get one error with
some instantiations and a different one with others.

>> Second, if I try to use a Vector rather than an Ordered_Map, I am told
>> that:
>> test2.adb:97:05: error: instantiation error at line 12
>> test2.adb:97:05: error: no visible subprogram matches the specification for "<"
>> It would seem that vector cursors can't be compared using < (at least by
>> default).  Maybe the installation needs more arguments.
>
> Vector has a proper index type. All you have to do is. Given
>
>    package Integer_Vectors is
>       new Ada.Containers.Vectors (Integer, Integer);
>
> Wrap Element into a function:
>
>    V : Integer_Vectors.Vector;
>    function Element (Index : Integer) return Integer is
>    begin
>       return V.Element (Index);
>    end Element;
>    ...
>
> and use the wrapper.

Sure, but the hope was to write something that does not need new
code for new situations.  That's what makes it reusable.

>> Anyway, I am still not sure how to write a generic test for an empty
>> range.
>
> The problem is that the implementation of Cursor that breaks
> abstraction. The abstraction of an argument does not permit ideal
> non-values. Cursors and pointers have non-values. So if you want to test
> for non-values ahead, instead of surprising the function, you need to add a
> test for value validity to the abstraction:
>
> generic
>    -- Ordered argument
>    type Argument_Type is private;
>    with function Valid (Value : Argument_Type) return Boolean is <>;
>    ...
> package Generic_Arguments is
>
> Then you would pass Has_Element for it. For integers you would use wrapped
> X'Valid (there is no Integer'Valid, unfortunately. Only X'Valid where X is
> an object).

It's definitely getting what I call cumbersome.

>> It's possible I was not clear about what I was aiming for.  I was hoping
>> to be able to find the maximum of some arbitrary function, taking the
>> function's arguments from any sequential collection.
>
> That is a different abstraction. You need a generic collection instead of
> generic ordered values. E.g.
>
> generic
>    with package Arguments is new Ada.Containers.Ordered_Sets (<>);
>    with package Values is new Generic_Values (<>);
> package Generic_Comparable_Valued is
>    use Arguments, Values;
>    function Maximum_At
>             (  Domain : Set;
>                Func : access function (Argument : Element_Type)
>                       return Value_Type
>             )  return Value_Type;
>    -- Other useless functions
> end Generic_Comparable_Valued;
>
> package body Generic_Comparable_Valued is
>    function Maximum_At
>             (  Domain : Set;
>                Func : access function (Argument : Element_Type)
>                       return Value_Type
>             )  return Value_Type is
>       Max      : Value_Type;
>       Value    : Value_Type;
>       Position : Cursor;
>    begin
>       if Domain.Is_Empty then
>          raise Constraint_Error with "Empty set";
>       end if;
>       Position := Domain.First;
>       Max := Func (Element (Position));
>       while Position /= Domain.Last loop
>          Position := Next (Position);
>          Value := Func (Element (Position));
>          if Max < Value then
>             Max := Value;
>          end if;
>       end loop;
>       return Max;
>    end Maximum_At;
> end Generic_Comparable_Valued;
>
>> Either a simple
>> range of values, an array or vector of values, a list of values or even
>> an ordered map of values -- any ordered list of values.
>
> In practice such abstraction have too much physical and mental
> overhead. E.g. large sets of values implemented differently from
> Ada.Containers.Ordered_Sets depending on the operations required. For
> example, let you need a set complement? Usually programmers simply stick
> with software patterns instead. Too much reliance of libraries make
> programs incoherent.

The core of my Haskell solution is just a function decimalRepeatLength
that returns the repeat length given a divisor.  But once I'd got the
answer (by applying it to 2 to 999 and getting the maximum) I wondered
what would happen if the numbers were not in a simple range.  Is it easy
to write a `maximisedOver` function that finds the maximum of some
function over any ordered collection (technically, a "foldable" type in
Haskell).

Well, yes, it is easy:

  function `maximisedOver` anything = maximum (fmap function anything)

so the solution to the project Euler problem is just

  decimalRepeatLength `maximisedOver` [2..999]

but I can also find the maximum of this (or any other suitable) function
over an array, a hash map, a vector... whatever.  No code changes
anywhere.  It even works with arrays of any number of dimensions
regardless of the index bounds.

maximisedOver is genuinely generic and reusable.

I don't think this is incoherent.  The Haskell libraries ensure that any
collection that is logically foldable is indeed foldable.

>> The bottom line is the last argument should be something very general
>> like the Period function.
>> A fix (though it's not really ideal) would be to use function
>> composition here (inventing . as the composition operator):
>>    Map_Functions.Maximum_At (X.First, X.Last, Period'Access
>> . Element'Access)
>> but I don't think Ada has a function composition operator, does it?
>
> No as it would require closures.

What closure is required for a function composition?  There is no
environment to "close over".

> So you can have a generic composition
> operator, no problem, but not a first-class one. However you can simply add
> Maximum_At with four arguments to the package.

This may be the closest we can get with Ada.

>> Another solution would be to write Maximum_At so that it knows it has a
>> cursor argument, but then I don't think it would work for native arrays,
>> would it?  And we'd loose plain ranges altogether.
>
> You can write a generic package creating array cursors:
>
> generic
>    type Index_Type is (<>);
>    type Element_Type is private;
>    type Array_Type is array (Index_Type range <>) of Element_Type;
> package Array_Cursors is
>    type Cursor is private;
>    function First (Container : Array_Type) return Cursor;
>    function Element (Position : Cursor) return Element_Type;
>    function "<" (Left, Right : Cursor) return Boolean;
>    ...
> private
>    package Dirty_Tricks is
>       new System.Address_To_Access_Conversions (Array_Type);
>    use Dirty_Tricks;
>    type Cursor is record
>       Domain : Object_Pointer;
>       Index  : Index_Type;
>    end record;
> end Array_Cursors;
>
> package body Array_Cursors is
>    function "<" (Left, Right : Cursor) return Boolean is
>    begin
>       if Left.Domain = null or else Left.Domain /= Right.Domain then
>          raise Constraint_Error with "Incomparable cursors";
>       end if;
>       return Left.Index < Right.Index;
>    end "<";
>
>    function Element (Position : Cursor) return Element_Type is
>    begin
>       if Position.Domain = null or else
>          Position.Index not in Position.Domain'Range
>       then
>          raise Constraint_Error with "Invalid cursor";
>       else
>          return Position.Domain (Position.Index);
>       end if;
>    end Element;
>
>    function First (Container : Array_Type) return Cursor is
>    begin
>       if Container'Length = 0 then
>          raise Constraint_Error with "Empty array";
>       else
>          return (To_Pointer (Container'Address), Container'First);
>       end if;
>    end First;
>
> end Array_Cursors;

That's a lot just to use something that is supposed to be reusable.

>> You seem to be on your own as far as helping out is concerned!
>
> Because it started as a numeric puzzle. You should have asked directly
> about generics or tagged types instead.

It only occurred to me after writing the non-generic solution.  I
remember Ada as being something of a pioneer in it's attempt to provide
generic solutions, so I wondered how far things had come.  I don't think
something really widely reusable is possible in this case.

-- 
Ben.

^ permalink raw reply	[relevance 0%]

* Re: project euler 26
  @ 2023-09-07  9:02  4%                               ` Dmitry A. Kazakov
  2023-09-08  1:32  0%                                 ` Ben Bacarisse
  0 siblings, 1 reply; 53+ results
From: Dmitry A. Kazakov @ 2023-09-07  9:02 UTC (permalink / raw)


On 2023-09-07 01:32, Ben Bacarisse wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On 2023-09-06 17:16, Ben Bacarisse wrote:
>>
>>> I am curious to know how reusable this is.  Can the packages be
>>> instantiated in such a way that the argument ranges over the elements
>>> of, say, and Ordered_Map?
>>
>> Sure:
>>
>>     with Ada.Containers.Ordered_Maps;
>>
>>     package Integer_Maps is
>>        new Ada.Containers.Ordered_Maps (Integer, Integer);
>>     use Integer_Maps;
>>     package Cursor_Arguments is new Generic_Arguments (Cursor);
> 
> Ah!  So the arguments correspond to the "with" functions in the order
> listed, and, since Cursor already has Next, there no need to specify
> anything.

Yes, because the formal argument is

    with function Next (Value : Argument_Type)
       return Argument_Type is <>;

If it were

    with function Next (Value : Argument_Type)
       return Argument_Type;

You would have to specify the actual. The part "is <>" tells to match a 
visible function Next.

> There are a couple of details that prevent your Maximum_At function from
> working properly in this case though.  First, we can't have an empty
> map, because X.Last can't be compared with X.First when either is
> No_Element, so the test for Right < Left fails before the desired error
> can be raised.

Yes, cursors is bad idea, in the end they all are pointers. No_Element 
is an equivalent of null which shows.

However Maximum_At will propagate Constraint_Error if either of the 
bounds is No_Element. So the implementation would work.

> Second, if I try to use a Vector rather than an Ordered_Map, I am told
> that:
> 
> test2.adb:97:05: error: instantiation error at line 12
> test2.adb:97:05: error: no visible subprogram matches the specification for "<"
> 
> It would seem that vector cursors can't be compared using < (at least by
> default).  Maybe the installation needs more arguments.

Vector has a proper index type. All you have to do is. Given

    package Integer_Vectors is
       new Ada.Containers.Vectors (Integer, Integer);

Wrap Element into a function:

    V : Integer_Vectors.Vector;
    function Element (Index : Integer) return Integer is
    begin
       return V.Element (Index);
    end Element;
    ...

and use the wrapper.

> Anyway, I am still not sure how to write a generic test for an empty
> range.

The problem is that the implementation of Cursor that breaks 
abstraction. The abstraction of an argument does not permit ideal 
non-values. Cursors and pointers have non-values. So if you want to test 
for non-values ahead, instead of surprising the function, you need to 
add a test for value validity to the abstraction:

generic
    -- Ordered argument
    type Argument_Type is private;
    with function Valid (Value : Argument_Type) return Boolean is <>;
    ...
package Generic_Arguments is

Then you would pass Has_Element for it. For integers you would use 
wrapped X'Valid (there is no Integer'Valid, unfortunately. Only X'Valid 
where X is an object).

> It's possible I was not clear about what I was aiming for.  I was hoping
> to be able to find the maximum of some arbitrary function, taking the
> function's arguments from any sequential collection.

That is a different abstraction. You need a generic collection instead 
of generic ordered values. E.g.

generic
    with package Arguments is new Ada.Containers.Ordered_Sets (<>);
    with package Values is new Generic_Values (<>);
package Generic_Comparable_Valued is
    use Arguments, Values;
    function Maximum_At
             (  Domain : Set;
                Func : access function (Argument : Element_Type)
                       return Value_Type
             )  return Value_Type;
    -- Other useless functions
end Generic_Comparable_Valued;

package body Generic_Comparable_Valued is
    function Maximum_At
             (  Domain : Set;
                Func : access function (Argument : Element_Type)
                       return Value_Type
             )  return Value_Type is
       Max      : Value_Type;
       Value    : Value_Type;
       Position : Cursor;
    begin
       if Domain.Is_Empty then
          raise Constraint_Error with "Empty set";
       end if;
       Position := Domain.First;
       Max := Func (Element (Position));
       while Position /= Domain.Last loop
          Position := Next (Position);
          Value := Func (Element (Position));
          if Max < Value then
             Max := Value;
          end if;
       end loop;
       return Max;
    end Maximum_At;
end Generic_Comparable_Valued;

> Either a simple
> range of values, an array or vector of values, a list of values or even
> an ordered map of values -- any ordered list of values.

In practice such abstraction have too much physical and mental overhead. 
E.g. large sets of values implemented differently from 
Ada.Containers.Ordered_Sets depending on the operations required. For 
example, let you need a set complement? Usually programmers simply stick 
with software patterns instead. Too much reliance of libraries make 
programs incoherent.

> The bottom line is the last argument should be something very general
> like the Period function.
> 
> A fix (though it's not really ideal) would be to use function
> composition here (inventing . as the composition operator):
> 
>    Map_Functions.Maximum_At (X.First, X.Last, Period'Access . Element'Access)
> 
> but I don't think Ada has a function composition operator, does it?

No as it would require closures. So you can have a generic composition 
operator, no problem, but not a first-class one. However you can simply 
add Maximum_At with four arguments to the package.

> Another solution would be to write Maximum_At so that it knows it has a
> cursor argument, but then I don't think it would work for native arrays,
> would it?  And we'd loose plain ranges altogether.

You can write a generic package creating array cursors:

generic
    type Index_Type is (<>);
    type Element_Type is private;
    type Array_Type is array (Index_Type range <>) of Element_Type;
package Array_Cursors is
    type Cursor is private;
    function First (Container : Array_Type) return Cursor;
    function Element (Position : Cursor) return Element_Type;
    function "<" (Left, Right : Cursor) return Boolean;
    ...
private
    package Dirty_Tricks is
       new System.Address_To_Access_Conversions (Array_Type);
    use Dirty_Tricks;
    type Cursor is record
       Domain : Object_Pointer;
       Index  : Index_Type;
    end record;
end Array_Cursors;

package body Array_Cursors is
    function "<" (Left, Right : Cursor) return Boolean is
    begin
       if Left.Domain = null or else Left.Domain /= Right.Domain then
          raise Constraint_Error with "Incomparable cursors";
       end if;
       return Left.Index < Right.Index;
    end "<";

    function Element (Position : Cursor) return Element_Type is
    begin
       if Position.Domain = null or else
          Position.Index not in Position.Domain'Range
       then
          raise Constraint_Error with "Invalid cursor";
       else
          return Position.Domain (Position.Index);
       end if;
    end Element;

    function First (Container : Array_Type) return Cursor is
    begin
       if Container'Length = 0 then
          raise Constraint_Error with "Empty array";
       else
          return (To_Pointer (Container'Address), Container'First);
       end if;
    end First;

end Array_Cursors;

> But then (I think) the only function one could pass would be something
> like Element as in you example above.  Using an ordered set of integers
> would not allow
> 
>    Map_Functions.Maximum_At (Set.First, Set.Last, Period'Access)
> 
> would it?

Ordered_Set cursors are ordered like Ordered_Map ones, so it should work.

>>> I am asking you but I am also the group.  I appreciate your help,
>>> but don't want you to feel any obligation to keep helping!
>>
>> No problem.
> 
> You seem to be on your own as far as helping out is concerned!

Because it started as a numeric puzzle. You should have asked directly 
about generics or tagged types instead.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49  6% Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
  2023-02-14  9:35  6% ` Jeffrey R.Carter
  2023-03-15 10:05  6% ` Marius Amado-Alves
@ 2023-03-15 14:24  6% ` Brad Moore
  2 siblings, 0 replies; 53+ results
From: Brad Moore @ 2023-03-15 14:24 UTC (permalink / raw)


On Tuesday, February 14, 2023 at 1:49:55 AM UTC-7, reinert wrote:
> Hello, 
> , 
> Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort. An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free". 
> 
> I would like to get arguments for and against these two alternatives. 
> 
> reinert

I might use the generic sorting for example, for the case where the data is more static and needs to be sorted once, whereas I'd use an ordered set if the data is continuously being updated and manipulated, or if I needed set semantics.

Brad

^ permalink raw reply	[relevance 6%]

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49  6% Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
  2023-02-14  9:35  6% ` Jeffrey R.Carter
@ 2023-03-15 10:05  6% ` Marius Amado-Alves
  2023-03-15 14:24  6% ` Brad Moore
  2 siblings, 0 replies; 53+ results
From: Marius Amado-Alves @ 2023-03-15 10:05 UTC (permalink / raw)


> Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort. An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free". 
> 
> I would like to get arguments for and against these two alternatives. 
> 
> reinert

Sets have slightly stricter semantics, namely no duplicates. Normally, if the real data has this semantics, you should use sets (and populate with Include or else catch the exception raised upon trying to Insert a duplicate).

^ permalink raw reply	[relevance 6%]

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14 10:46  6%   ` reinert
@ 2023-02-14 18:48  6%     ` G.B.
  0 siblings, 0 replies; 53+ results
From: G.B. @ 2023-02-14 18:48 UTC (permalink / raw)


On 14.02.23 11:46, reinert wrote:
> My main argument for using Ordered_Sets is that it seems to be less verbose and somehow garanteres sorting. Myset.Last/First always provides the "largest"/"smallest" element.

You could measure performance of operations
that you find critical, given a typical number
of elements in the set. If there isn't any operation
that is particularly critical, some weighted
average of all set operations might be of interest.

Two similar data structures might both use a common
algorithm, such as sorting. If a program uses both
data structures, then having just one algorithm
might be advantageous, if only for the size of
the executable.

^ permalink raw reply	[relevance 6%]

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  9:35  6% ` Jeffrey R.Carter
@ 2023-02-14 10:46  6%   ` reinert
  2023-02-14 18:48  6%     ` G.B.
  0 siblings, 1 reply; 53+ results
From: reinert @ 2023-02-14 10:46 UTC (permalink / raw)


My main argument for using Ordered_Sets is that it seems to be less verbose and somehow garanteres sorting. Myset.Last/First always provides the "largest"/"smallest" element.

reinert



^ permalink raw reply	[relevance 6%]

* Re: Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
  2023-02-14  8:49  6% Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
@ 2023-02-14  9:35  6% ` Jeffrey R.Carter
  2023-02-14 10:46  6%   ` reinert
  2023-03-15 10:05  6% ` Marius Amado-Alves
  2023-03-15 14:24  6% ` Brad Moore
  2 siblings, 1 reply; 53+ results
From: Jeffrey R.Carter @ 2023-02-14  9:35 UTC (permalink / raw)


On 2023-02-14 09:49, reinert wrote:
> 
> Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort.  An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free".
> 
> I would like to get arguments for and against these two alternatives.

Both should be O(NlogN), so the distinction is which works better for what you 
do with them after they are sorted.

-- 
Jeff Carter
"[B]ecause of our experience in security, we are convinced
that C is too error-prone. Its loose typing, its unsafe
bitfields management, too many compiler dependent behaviors,
etc. easily lead to vulnerabilities."
EwoK developers
163

^ permalink raw reply	[relevance 6%]

* Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ?
@ 2023-02-14  8:49  6% reinert
  2023-02-14  9:35  6% ` Jeffrey R.Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 53+ results
From: reinert @ 2023-02-14  8:49 UTC (permalink / raw)


Hello,

Sometimes, I have to sort records. One possibility is to use Generig_Sorting under Ada.Containers.Vectors and eksplicitly use Sort.  An alternative is to use Ada.Containders.Ordered_Sets and somehow get sorting "for free". 

I would like to get arguments for and against these two alternatives.

reinert

^ permalink raw reply	[relevance 6%]

* Re: Question about sets and expression
  @ 2017-05-09  5:48  6%     ` reinert
  0 siblings, 0 replies; 53+ results
From: reinert @ 2017-05-09  5:48 UTC (permalink / raw)


Could anybody try this simple program below?

I get the output (debian, gnat-4.9):

--------------------------------------------------------------------------
** A: 
** B: 

raised PROGRAM_ERROR : test1b.adb:29 finalize/adjust raised exception
--------------------------------------------------------------------------
 Why "finalize/adjust raised exception" ?

reinert
https://korsnesbiocomputing.no/


with Ada.Numerics;
use  Ada.Numerics;
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Containers.Ordered_Sets;

with Text_IO;use Text_IO;
procedure test1b is

   subtype real is Float;
   subtype degree_t is real range 0.0 .. 360.0;
   package gra is new Ada.Numerics.Generic_Real_Arrays (real);
   use gra;
   subtype real_vector2d is gra.real_vector (1 .. 2);
   type target_t is (cnil,C000,C001,C002,C003,C004);
   package cell_names_sets is new Ada.Containers.Ordered_Sets (target_t);

   type cell_state_t is
     (live,
      apoptosis,
      necrotic,
      dead,
      mitosis,
      mitotic_catastrophe,
      refusion,
      unknown,
      out_of_scene,
      ghost);

   type cell_observation_t is record
      id                  : target_t;
      state               : cell_state_t         := live;
      r, dr               : real_vector2d        := (0.0, 0.0);
      axis                : degree_t;
      children1           : cell_names_sets.set  := cell_names_sets.empty_set;
      pre_cell, next_cell : target_t             := cnil;
   end record;

   function "<"
     (left, right : cell_observation_t) return Boolean is
     (left.id < right.id);
   function "="
     (left, right : cell_observation_t) return Boolean is
     (left.id = right.id);

    package cell_observation_set is new Ada.Containers.Ordered_Sets
     (Element_Type => cell_observation_t);
    use cell_observation_set;

    os : cell_observation_set.set := to_set((id => C003,others => <>));
    c : cell_observation_t;
    d : cell_observation_t := (id => Cnil,others => <>);

begin

 Put_Line(" ** A: ");
 c := (if not os.is_empty then os.first_element else d);
 Put_Line(" ** B: ");
 c := (if not os.is_empty then os.first_element else (id => Cnil, others => <>));
 Put_Line(" ** C ");

end test1b;


^ permalink raw reply	[relevance 6%]

* Re: Question about sets and expression
    2017-05-08 17:03  5%   ` reinert
@ 2017-05-08 17:04  5%   ` reinert
  1 sibling, 0 replies; 53+ results
From: reinert @ 2017-05-08 17:04 UTC (permalink / raw)


On Monday, May 8, 2017 at 6:06:52 PM UTC+2, Robert Eachus wrote:
> On Monday, May 8, 2017 at 11:53:23 AM UTC-4, reinert wrote:
>  
> > I did not manage to make a simple test program for this problem,
> > but maybe someone can give me a hint here. I start to be "blind" :-)
> > 
> > os is here an Ordered_Set (not empty). The first part seems OK,
> > but the second part is confusing (craches).
> 
> Trying to diagnose the problem without the declarations is difficult.  I suspect
> that c := (id => Cnil, others => <>);  is trying to assign an unbounded array with that others part.

OK, sorry. 

c: cell_observation_t; 

where simply: 

   type cell_observation_t is record 
      id                  : cell_names1.target_t; 
      state               : cell_state_t         := live; 
      r, dr               : real_vector2d        := (0.0, 0.0); 
      axis                : degree_t; 
      children1           : cell_names1.cell_names_sets.set := cell_names1.cell_names_sets.empty_set; 
      pre_cell, next_cell : target_t             := cnil; 
   end record; 

"children1" is Ada.Containers.Ordered_Sets (without any defined bound): 

 package cell_names_sets is new Ada.Containers.Ordered_Sets (target_t); 

 "target_t" is an enumaration type. 


I hoped that someone has encountered similar with expressions and could give a hint. Maybe I have destroyed the Ordered_Set somewhere... 

I use GNAT under debian, updated. gnat-4.9. 

reinert 


^ permalink raw reply	[relevance 5%]

* Re: Question about sets and expression
  @ 2017-05-08 17:03  5%   ` reinert
  2017-05-08 17:04  5%   ` reinert
  1 sibling, 0 replies; 53+ results
From: reinert @ 2017-05-08 17:03 UTC (permalink / raw)


On Monday, May 8, 2017 at 6:06:52 PM UTC+2, Robert Eachus wrote:
> On Monday, May 8, 2017 at 11:53:23 AM UTC-4, reinert wrote:
>  
> > I did not manage to make a simple test program for this problem,
> > but maybe someone can give me a hint here. I start to be "blind" :-)
> > 
> > os is here an Ordered_Set (not empty). The first part seems OK,
> > but the second part is confusing (craches).
> 
> Trying to diagnose the problem without the declarations is difficult.  I suspect
> that c := (id => Cnil, others => <>);  is trying to assign an unbounded array with that others part.

OK, sorry.

c: cell_observation_t;

where simply:

   type cell_observation_t is record
      id                  : cell_names1.target_t;
      state               : cell_state_t         := live;
      r, dr               : real_vector2d        := (0.0, 0.0);
      axis                : degree_t;
      children1           : cell_names1.cell_names_sets.set := cell_names1.cell_names_sets.empty_set;
      pre_cell, next_cell : target_t             := cnil;
   end record;

"children1" is Ada.Containers.Ordered_Sets (without any defined bound):

 package cell_names_sets is new Ada.Containers.Ordered_Sets (target_t);

 "target_t" is an enumaration type.


My hoped that someone has encountered similar with expressions and could give a hint. Maybe I have destroyed the Ordered_Set somewhere...

I use GNAT under debian, updated. gnat-4.9.

reinert


^ permalink raw reply	[relevance 5%]

* Re: raised PROGRAM_ERROR : XXXXXX finalize/adjust raised exception
  2017-05-06 14:57  6%   ` reinert
@ 2017-05-06 15:46  0%     ` Jeffrey R. Carter
  0 siblings, 0 replies; 53+ results
From: Jeffrey R. Carter @ 2017-05-06 15:46 UTC (permalink / raw)


On 05/06/2017 04:57 PM, reinert wrote:
>
> Can Ada.Containers.Ordered_Sets include a controlled component?

ARM A.18.7 says, "The type Set needs finalization (see 7.6).", which effectively 
means it is controlled. This is true of all the unbounded containers.

It's possible but unlikely that your compiler's implementation of Ordered_Sets 
has an error. Operations on sets should leave the set in a valid state for 
finalization. So I don't see how having a set component could cause this.

-- 
Jeff Carter
"[M]any were collected near them, ... to
enjoy the sight of a dead young lady, nay,
two dead young ladies, for it proved twice
as fine as the first report."
Persuasion
155

^ permalink raw reply	[relevance 0%]

* Re: raised PROGRAM_ERROR : XXXXXX finalize/adjust raised exception
  2017-05-06 14:59  6%   ` reinert
@ 2017-05-06 15:05  4%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 53+ results
From: Dmitry A. Kazakov @ 2017-05-06 15:05 UTC (permalink / raw)


On 2017-05-06 16:59, reinert wrote:
> On Saturday, May 6, 2017 at 4:08:09 PM UTC+2, Jeffrey R. Carter wrote:
>
>> Probably your type has a controlled component, since the type itself is not controlled.
>
> Can Ada.Containers.Ordered_Sets include a controlled component?
>
> In my code (record) given above
>
> children1           : cell_names1.cell_names_sets.set;
>
> is of type Ada.Containers.Ordered_Sets.
> In case this cause the program error, how to solve the problem?

It is possible but doubtful that Ada.Containers.Ordered_Sets has a bug. 
It is more likely an induced error. Use exceptions tracing to see what 
exactly goes on before Program_Error happens.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: raised PROGRAM_ERROR : XXXXXX finalize/adjust raised exception
    2017-05-06 14:57  6%   ` reinert
@ 2017-05-06 14:59  6%   ` reinert
  2017-05-06 15:05  4%     ` Dmitry A. Kazakov
  1 sibling, 1 reply; 53+ results
From: reinert @ 2017-05-06 14:59 UTC (permalink / raw)


On Saturday, May 6, 2017 at 4:08:09 PM UTC+2, Jeffrey R. Carter wrote:

> Probably your type has a controlled component, since the type itself is not controlled.
>

Can Ada.Containers.Ordered_Sets include a controlled component? 

In my code (record) given above 

children1           : cell_names1.cell_names_sets.set; 

is of type Ada.Containers.Ordered_Sets. 
In case this cause the program error, how to solve the problem? 

reinert 


^ permalink raw reply	[relevance 6%]

* Re: raised PROGRAM_ERROR : XXXXXX finalize/adjust raised exception
  @ 2017-05-06 14:57  6%   ` reinert
  2017-05-06 15:46  0%     ` Jeffrey R. Carter
  2017-05-06 14:59  6%   ` reinert
  1 sibling, 1 reply; 53+ results
From: reinert @ 2017-05-06 14:57 UTC (permalink / raw)


On Saturday, May 6, 2017 at 4:08:09 PM UTC+2, Jeffrey R. Carter wrote:
 Probably your 
> type has a controlled component, since the type itself is not controlled.
> 
> -- 

Can Ada.Containers.Ordered_Sets include a controlled component?

I my code (record) given above

children1           : cell_names1.cell_names_sets.set;

is of type Ada.Containers.Ordered_Sets.
In case this cause the program error, how to solve the problem?

reinert


^ permalink raw reply	[relevance 6%]

* Re: New to Ada need help implementing Warshall's algorithm
  2016-09-23  4:31  5% ` Shark8
@ 2016-09-23 14:54  0%   ` James Brewer
  0 siblings, 0 replies; 53+ results
From: James Brewer @ 2016-09-23 14:54 UTC (permalink / raw)


On Thursday, September 22, 2016 at 11:31:53 PM UTC-5, Shark8 wrote:
> On Wednesday, September 21, 2016 at 4:05:12 PM UTC-6, James Brewer wrote:
> > Hello I hope this is right forum for this question. I have been asked to write a program that implements Warshall's algorithm using Ada. The problem, I have never written an Ada program and I a limited time frame to put this together.
> > I have have the IDE installed and am in the process of writing some rudimentary programs to familiarize myself with the language but I'm afraid that I may run out of time. 
> > 
> > The input data I have is a series of connections between 7 to 9 entities that would be stored in a file.
> > 
> > examples: A->B  A->D  C->D 
> >           alice->bob  alice->larry bob -> larry
> >            1 -> 3  1 -> 5  2 -> 5
> > 
> > Any help you could offer would be greatly appreciated.
> > Thanks
> 
> 
> This sounds kind of like homework, is it?
> 
> In any case, what you could do is use Ada.Containers to handle the problem:
> * Create an enumeration for nodes, perhaps Node_01 to Node_10.
> * Instantiate Ada.Containers.Indefinite_Vectors with that enumeration as key and element as string. (This is to associate your input-variables w/ the enumeration.)
> * Instantiate Ada.Containers.Ordered_Sets with the enumeration; this is to represent node-connections.
> * Instantiate Ada.Containers.Indefinite_Ordered_Maps with the Set-type from the above as the element and the enumeration as the key. 
> 
> The rest is left to you.

It is a homework of sorts, but not in the way you'd normally think.  The instructor uses Ada when teaching algorithms for the examples but he expects you to teach yourself Ada on your own while trying to learn the algorithms. This is a bit daunting when you don't know what the language can and cannot do.

Thanks for the help, I appreciate it.  

^ permalink raw reply	[relevance 0%]

* Re: New to Ada need help implementing Warshall's algorithm
  @ 2016-09-23  4:31  5% ` Shark8
  2016-09-23 14:54  0%   ` James Brewer
  0 siblings, 1 reply; 53+ results
From: Shark8 @ 2016-09-23  4:31 UTC (permalink / raw)


On Wednesday, September 21, 2016 at 4:05:12 PM UTC-6, James Brewer wrote:
> Hello I hope this is right forum for this question. I have been asked to write a program that implements Warshall's algorithm using Ada. The problem, I have never written an Ada program and I a limited time frame to put this together.
> I have have the IDE installed and am in the process of writing some rudimentary programs to familiarize myself with the language but I'm afraid that I may run out of time. 
> 
> The input data I have is a series of connections between 7 to 9 entities that would be stored in a file.
> 
> examples: A->B  A->D  C->D 
>           alice->bob  alice->larry bob -> larry
>            1 -> 3  1 -> 5  2 -> 5
> 
> Any help you could offer would be greatly appreciated.
> Thanks


This sounds kind of like homework, is it?

In any case, what you could do is use Ada.Containers to handle the problem:
* Create an enumeration for nodes, perhaps Node_01 to Node_10.
* Instantiate Ada.Containers.Indefinite_Vectors with that enumeration as key and element as string. (This is to associate your input-variables w/ the enumeration.)
* Instantiate Ada.Containers.Ordered_Sets with the enumeration; this is to represent node-connections.
* Instantiate Ada.Containers.Indefinite_Ordered_Maps with the Set-type from the above as the element and the enumeration as the key. 

The rest is left to you.

^ permalink raw reply	[relevance 5%]

* Re: Change in GCC 5.1.0
  2015-04-26 16:51  5% Change in GCC 5.1.0 Simon Wright
@ 2015-04-26 18:42  0% ` jan.de.kruyf
  0 siblings, 0 replies; 53+ results
From: jan.de.kruyf @ 2015-04-26 18:42 UTC (permalink / raw)


On Sunday, April 26, 2015 at 6:51:54 PM UTC+2, Simon Wright wrote:
> GCC 4.9.1 (and presumably GNAT GPL 2014) allowed variable indexing on a
> Set, even though there was no Variable_Indexing aspect in the spec.
> 
> GCC 5.1.0 doesn't.
> 
> So this code (from Gprbuild GPL 2014) compiled and, presumably, worked
> when it shouldn't have:
> 
>    with Ada.Containers.Ordered_Sets;
>    procedure Iteration is
>       type Slave is new Integer;
>       package Slave_S is new Ada.Containers.Ordered_Sets
>         (Element_Type => Slave);
>       Pool : Slave_S.Set;
>       procedure Iterate (Proc : access procedure (S : in out Slave)) is
>       begin
>          for C in Pool.Iterate loop
>             declare
>                S : Slave := Slave_S.Element (C);
>             begin
>                Proc (S);
>                Pool (C) := S;     -- <<<<<<<<<<<<<<< wrong
>             end;
>          end loop;
>       end Iterate;
>    begin
>       null;
>    end Iteration;
> 
> The thing about an (ordered) set is that replacing an element must
> involve re-ordering the set, in case the element's position has
> changed. So the compilable code in this case is
> 
>                Pool.Replace_Element (C, S);
> 
> That said, that looks awfully like tampering to me (if the order
> changes, anyway). I await Gprbuild GPL 2015 with interest.



Hi Simon,
Just to dampen your expectations a bit:
-------------------
$ gcc --version
gcc (GCC) 4.7.4 20140401 for GNAT GPL gpl-2014 (20140405)
Copyright (C) 2012 Free Software Foundation, Inc.
-------------------

And I had Ada code braking before, that should never have passed the compiler in the first place (shame on me).

On another note: I promised to do a write up on my embedded runtime development.. Well the runtime is going ok, but the laptop with my notes on it was nicked, so I went through the moves of rebuilding my development system etc, the last couple of weeks. The work itself was safe though.
And by the way there is still a fair bit of 32 bit stuff in the present Gnat release for Linux.

So as soon as I see that the board is running ok, i.e. the runtime is reasonably tested, I will try to do a summary.


Cheers,

j.



^ permalink raw reply	[relevance 0%]

* Change in GCC 5.1.0
@ 2015-04-26 16:51  5% Simon Wright
  2015-04-26 18:42  0% ` jan.de.kruyf
  0 siblings, 1 reply; 53+ results
From: Simon Wright @ 2015-04-26 16:51 UTC (permalink / raw)


GCC 4.9.1 (and presumably GNAT GPL 2014) allowed variable indexing on a
Set, even though there was no Variable_Indexing aspect in the spec.

GCC 5.1.0 doesn't.

So this code (from Gprbuild GPL 2014) compiled and, presumably, worked
when it shouldn't have:

   with Ada.Containers.Ordered_Sets;
   procedure Iteration is
      type Slave is new Integer;
      package Slave_S is new Ada.Containers.Ordered_Sets
        (Element_Type => Slave);
      Pool : Slave_S.Set;
      procedure Iterate (Proc : access procedure (S : in out Slave)) is
      begin
         for C in Pool.Iterate loop
            declare
               S : Slave := Slave_S.Element (C);
            begin
               Proc (S);
               Pool (C) := S;     -- <<<<<<<<<<<<<<< wrong
            end;
         end loop;
      end Iterate;
   begin
      null;
   end Iteration;

The thing about an (ordered) set is that replacing an element must
involve re-ordering the set, in case the element's position has
changed. So the compilable code in this case is

               Pool.Replace_Element (C, S);

That said, that looks awfully like tampering to me (if the order
changes, anyway). I await Gprbuild GPL 2015 with interest.

^ permalink raw reply	[relevance 5%]

* Re: BDD package in Ada.
  @ 2015-04-08 21:30  4%     ` Randy Brukardt
  0 siblings, 0 replies; 53+ results
From: Randy Brukardt @ 2015-04-08 21:30 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]

"Vincent DIEMUNSCH" <vincent.diemunsch@gmail.com> wrote in message 
news:c7db12c1-10fa-40ee-a2df-ff8a8b2177bc@googlegroups.com...
>Le mercredi 8 avril 2015 08:38:19 UTC+2, Dmitry A. Kazakov a écrit :

>> I would not call it "fundamental". It is simply a tree with factored out
>> subtrees. Need not to be binary, BTW.
>A BINARY decision diagram needs to be binary, by definition. It is not 
>"simply" a tree,
> but a highly optimised data structure, not only by factoring the tree, but 
> through variable
> ordering, which is the key idea. (Briant's paper is about ORDERED BDD). It 
> is usefull
> for the implementation of Sets and operations on sets.

Sounds like premature optimization to me. If you want sets, use 
Ada.Containers.Ordered_Sets and see if it is fast enough. In the unlikely 
case that it is not, implement your own body to a similar specification 
using a different technology to handle the ordering.

The vast majority of uses of anything do not need "highly optimized" data 
structures. On top of which, it's likely that your implementer has spent 
plenty of time optimizing the standard containers, so it's quite likely that 
they will be faster than you might expect.

That's a lesson we all need to learn, and re-learn, and re-learn again, 
because "highly optimized data structures" are a lot more fun and satisfying 
to a programmer. But they're rarely actually needed. (I've made that mistake 
plenty of times.)

[Side note to another thread. That of course goes for GC as well. There is 
lots of junkware that doesn't need to be engineered well; that's why dynamic 
languages have such a following. But that's not Ada's target market.]

Whatever BDD is, it can't be very important since I've never heard of it 
until today. :-) I'm pretty sure I would have run across something that's 
actually fundamental in 30 years. YMMV.

                                                           Randy.


^ permalink raw reply	[relevance 4%]

* Re: A bad counterintuitive behaviour of Ada about OO
  2014-08-08 12:00  0%                                 ` J-P. Rosen
@ 2014-08-08 13:11  0%                                   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 53+ results
From: Dmitry A. Kazakov @ 2014-08-08 13:11 UTC (permalink / raw)


On Fri, 08 Aug 2014 14:00:26 +0200, J-P. Rosen wrote:

> Le 08/08/2014 12:53, Dmitry A. Kazakov a écrit :
>>> Moreover, classification is used in mathematics for the theory of
>>> numbers, which is not relevant to practical usage of numbers.
>> 
>> Having integers ordered is unpractical? Being them additive has no usage?
>> 
> Yes of course, but the /theory/ of it, and especially group theory etc.
> that you mentioned is not a programmer's concern.

How so? If integer is not ordered there is no "<" defined, if there is no
"<" how are you going to have an ordered map with integer keys?

>> I don't know which relationships are "conceptual" and which are not.
>> 
>> generic
>>    type Element_Type is private;
>>    with function "<" (Left, Right : Element_Type) return Boolean is <>;
>>    with function "=" (Left, Right : Element_Type) return Boolean is <>;
>> package Ada.Containers.Ordered_Sets is
>> 
>> Isn't all types acceptable as Element_Type a "conceptual" class?
>> 
> I argue they are not. If you provide an operation that operates on a
> class wide type, then it can be used only on types belonging to the
> class, which means there is a dependency between these types.

I don't see any dependency, but that was not the question. It was - do
private types with "<" and "=" form a "conceptual" class. Do acceptable
actual types of a generic form one?

> A generic can be applied to types that are not related in any way.

They are related in exactly the way that this generic can be applied to
them. Is the feature of being applicable in a generic relevant for
programmers? I think it is. 

> This reminds me of a (bad) example of inheritance I once saw in a book:
> the class "parrot" inherited from the class "human" because it needed
> the method "can_speak". I'm somewhat uncomfortable with the notion that
> a parrot is a special kind of human ;-). Well, it's a bad example
> because inheritance should not be used just to grab any method you need.

It is bad design, because the class of things that can speak is not the
class of humans. Parrots and humans certainly participate in some classes,
e.g. in Chordates, Tetrapoda etc.

> There must be some /conceptual/ dependence, i.e. some "is-a" dependency.
> That's what I meant: a generic "can_speak" function that could be
> instantiated on humans or parrots would be much less disturbing - to my
> taste.

It is incredibly disturbing because there is no difference between:

   function Can_Speak (X : Thing) return Boolean;

and

   function Is_Empty (X : Thing) return Boolean;

This is exactly the point why generics are untyped in their heart. There is
tight relationship between operations =, /=, <, >, >=, <=, 'Prev, 'Next of
an ordered set. This is what makes it such a thing. Inheriting to Ordered
tells to the reader all this in just one source line. Moreover, it allows
the compiler to check if the manifested type is indeed ordered and even
prove some of this like x=y <=> not x/=y. Compare this with generics. They
just name some operations and the programmer should guess about the purpose
of what the actual type should be. Yes there is no dependency ... on the
application domain. Just an ad-hoc mess.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 0%]

* Re: A bad counterintuitive behaviour of Ada about OO
  2014-08-08 10:53  4%                               ` Dmitry A. Kazakov
  2014-08-08 10:56  0%                                 ` Victor Porton
@ 2014-08-08 12:00  0%                                 ` J-P. Rosen
  2014-08-08 13:11  0%                                   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 53+ results
From: J-P. Rosen @ 2014-08-08 12:00 UTC (permalink / raw)


Le 08/08/2014 12:53, Dmitry A. Kazakov a écrit :
>> Moreover, classification is used in mathematics for the theory of
>> numbers, which is not relevant to practical usage of numbers.
> 
> Having integers ordered is unpractical? Being them additive has no usage?
> 
Yes of course, but the /theory/ of it, and especially group theory etc.
that you mentioned is not a programmer's concern.

> I don't know which relationships are "conceptual" and which are not.
> 
> generic
>    type Element_Type is private;
>    with function "<" (Left, Right : Element_Type) return Boolean is <>;
>    with function "=" (Left, Right : Element_Type) return Boolean is <>;
> package Ada.Containers.Ordered_Sets is
> 
> Isn't all types acceptable as Element_Type a "conceptual" class?
> 
I argue they are not. If you provide an operation that operates on a
class wide type, then it can be used only on types belonging to the
class, which means there is a dependency between these types.

A generic can be applied to types that are not related in any way.

This reminds me of a (bad) example of inheritance I once saw in a book:
the class "parrot" inherited from the class "human" because it needed
the method "can_speak". I'm somewhat uncomfortable with the notion that
a parrot is a special kind of human ;-). Well, it's a bad example
because inheritance should not be used just to grab any method you need.
There must be some /conceptual/ dependence, i.e. some "is-a" dependency.
That's what I meant: a generic "can_speak" function that could be
instantiated on humans or parrots would be much less disturbing - to my
taste.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[relevance 0%]

* Re: A bad counterintuitive behaviour of Ada about OO
  2014-08-08 10:53  4%                               ` Dmitry A. Kazakov
@ 2014-08-08 10:56  0%                                 ` Victor Porton
  2014-08-08 12:00  0%                                 ` J-P. Rosen
  1 sibling, 0 replies; 53+ results
From: Victor Porton @ 2014-08-08 10:56 UTC (permalink / raw)


Dmitry A. Kazakov wrote:

> On Fri, 08 Aug 2014 12:01:48 +0200, J-P. Rosen wrote:
> 
>> Le 08/08/2014 11:13, Dmitry A. Kazakov a écrit :
>>> How mathematics may not apply to the elementary types like Integer?
>> Because computer integers are not the same as mathematical ones, and the
>> way they are used are different.
> 
> Interesting, it was always OO proponents' argument that numbers are not
> numbers.
>  
>> Moreover, classification is used in mathematics for the theory of
>> numbers, which is not relevant to practical usage of numbers.
> 
> Having integers ordered is unpractical? Being them additive has no usage?
> 
>>> Do you propose not to formalize "some features"? This is not how Ada
>>> generics work anyway. "Some features" are formalized in Ada through
>>> formal generic parameters. The only difference to classes is that
>>> classes do that through types, while generics do in an untyped manner.
>> 
>> And those types must be related through inheritance, while generics may
>> be instantiated on types that have no conceptual relationship.
> 
> I don't know which relationships are "conceptual" and which are not.
> 
> generic
>    type Element_Type is private;
>    with function "<" (Left, Right : Element_Type) return Boolean is <>;
>    with function "=" (Left, Right : Element_Type) return Boolean is <>;
> package Ada.Containers.Ordered_Sets is
> 
> Isn't all types acceptable as Element_Type a "conceptual" class?

Making elementary classes would certainly require multiple inheritance (and 
even "virtual" multiple inheritance, in C++ terms).

I think it would be very hard to modify Ada standard to support this.

-- 
Victor Porton - http://portonvictor.org


^ permalink raw reply	[relevance 0%]

* Re: A bad counterintuitive behaviour of Ada about OO
  @ 2014-08-08 10:53  4%                               ` Dmitry A. Kazakov
  2014-08-08 10:56  0%                                 ` Victor Porton
  2014-08-08 12:00  0%                                 ` J-P. Rosen
  0 siblings, 2 replies; 53+ results
From: Dmitry A. Kazakov @ 2014-08-08 10:53 UTC (permalink / raw)


On Fri, 08 Aug 2014 12:01:48 +0200, J-P. Rosen wrote:

> Le 08/08/2014 11:13, Dmitry A. Kazakov a écrit :
>> How mathematics may not apply to the elementary types like Integer?
> Because computer integers are not the same as mathematical ones, and the
> way they are used are different.

Interesting, it was always OO proponents' argument that numbers are not
numbers.
 
> Moreover, classification is used in mathematics for the theory of
> numbers, which is not relevant to practical usage of numbers.

Having integers ordered is unpractical? Being them additive has no usage?

>> Do you propose not to formalize "some features"? This is not how Ada
>> generics work anyway. "Some features" are formalized in Ada through formal
>> generic parameters. The only difference to classes is that classes do that
>> through types, while generics do in an untyped manner.
> 
> And those types must be related through inheritance, while generics may
> be instantiated on types that have no conceptual relationship.

I don't know which relationships are "conceptual" and which are not.

generic
   type Element_Type is private;
   with function "<" (Left, Right : Element_Type) return Boolean is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Ordered_Sets is

Isn't all types acceptable as Element_Type a "conceptual" class?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 4%]

* Strange instantiation error with formal packages
@ 2013-11-19  5:57  7% ytomino
  0 siblings, 0 replies; 53+ results
From: ytomino @ 2013-11-19  5:57 UTC (permalink / raw)


Hello.
Please, consider below example:

---- 8< ----

with ada.containers.ordered_sets; -- any generic package
with g1;
with g2;
procedure main is
   package charsets is new ada.containers.ordered_sets (Character);
   package p1 is new g1 (charsets);
   package p1_n is new p1.nested;
   package p2 is new g2 (charsets, p1, p1_n);
begin
   null;
end main;

with ada.containers.ordered_sets;
generic
   with package sets is new ada.containers.ordered_sets(<>);
package g1 is
   generic
   package nested is
   end nested;
end g1;

with ada.containers.ordered_sets;
with g1;
generic
   with package sets is new ada.containers.ordered_sets(<>); -- *1
   with package p1 is new g1 (sets);
   with package p1_n is new p1.nested;
package g2 is
end g2;

---- >8 ----

This is OK, able to be compiled.

$ gnatmake -gnat2012 main.adb
gcc -c -gnat2012 main.adb
gcc -c -gnat2012 g1.ads
gcc -c -gnat2012 g2.ads
gnatbind -x main.ali
gnatlink main.ali

Then...
Remove the formal package "sets" from g2:

---- 8< ----

with ada.containers.ordered_sets;
with g1;
with g2;
procedure main is
   package charsets is new ada.containers.ordered_sets (Character);
   package p1 is new g1 (charsets);
   package p1_n is new p1.nested;
   package p2 is new g2 (p1, p1_n); -- "sets" is removed
begin
   null;
end main;

-- g1 is same as first example.

with g1;
generic
   -- "sets" is removed
   with package p1 is new g1 (<>); -- use a box instead of "sets"
   with package p1_n is new p1.nested;
package g2 is
end g2;

---- >8 ----

This is bad.

$ gnatmake -gnat2012 main.adb
gcc -c -gnat2012 main.adb
main.adb:8:30: actual parameter must be instance of "nested"
main.adb:8:30: instantiation abandoned
gnatmake: "main.adb" compilation error

Why?

I tried with gcc-4.8.1 and GNAT GPL 2012.


Regards.

--
Yuta Tomino

^ permalink raw reply	[relevance 7%]

* Re: extended membership tests
  2011-03-31  7:04  5% extended membership tests Dan
                   ` (2 preceding siblings ...)
  2011-03-31  9:28  0% ` AdaMagica
@ 2011-03-31 14:33  0% ` Robert A Duff
  3 siblings, 0 replies; 53+ results
From: Robert A Duff @ 2011-03-31 14:33 UTC (permalink / raw)


Dan <dan@irvine.com> writes:

> Here's a fun quiz to test your Ada2012 knowledge, based on an
> observation by Yannick Moy.

I won't answer, because I was involved in the discussion with Yannick.

> Consider this Ada 2012 procedure:
>
> with ada.containers.ordered_sets;
> procedure membership is
>     package int_sets is new ada.containers.ordered_sets(integer);
>     function "="(x,y: integer) return boolean is begin return true;
> end;
>     x: integer := 6;
>     y: integer := 12;
>     b1: boolean := x in y;
>     b2: boolean := x in int_sets.to_set(new_item => y);
> begin
>     null;
> end;

For extra credit, what happens if we replace b2 with:

    b3: boolean := int_sets.to_set(new_item => x)
                in int_sets.to_set(new_item => x)
                or int_sets.to_set(new_item => y);

;-)

- Bob



^ permalink raw reply	[relevance 0%]

* Re: extended membership tests
  2011-03-31  7:04  5% extended membership tests Dan
  2011-03-31  7:34  0% ` AdaMagica
  2011-03-31  8:05  0% ` Ludovic Brenta
@ 2011-03-31  9:28  0% ` AdaMagica
  2011-03-31 14:33  0% ` Robert A Duff
  3 siblings, 0 replies; 53+ results
From: AdaMagica @ 2011-03-31  9:28 UTC (permalink / raw)


>     package int_sets is new ada.containers.ordered_sets(integer);
>     x: integer := 6;
>     b2: boolean := x in int_sets.to_set(new_item => y);

Ah, my previous statement was not quite correct.
I didn't check, but I guess, sets are tagged, so the tested type is
tagged. Therefore the simple expression (x) must be convertible to the
tested type, which it isn't.
So the statement is illegal (as before, but for a different reason).



^ permalink raw reply	[relevance 0%]

* Re: extended membership tests
  2011-03-31  7:04  5% extended membership tests Dan
  2011-03-31  7:34  0% ` AdaMagica
@ 2011-03-31  8:05  0% ` Ludovic Brenta
  2011-03-31  9:28  0% ` AdaMagica
  2011-03-31 14:33  0% ` Robert A Duff
  3 siblings, 0 replies; 53+ results
From: Ludovic Brenta @ 2011-03-31  8:05 UTC (permalink / raw)


Dan wrote:
> Here's a fun quiz to test your Ada2012 knowledge, based on an
> observation by Yannick Moy.
>
> Consider this Ada 2012 procedure:
>
> with ada.containers.ordered_sets;
> procedure membership is
>     package int_sets is new ada.containers.ordered_sets(integer);
>     function "="(x,y: integer) return boolean is begin return true;
> end;
>     x: integer := 6;
>     y: integer := 12;
>     b1: boolean := x in y;
>     b2: boolean := x in int_sets.to_set(new_item => y);
> begin
>     null;
> end;
>
> Which of the following are true:
>   a)  b1 is true because 6 <= 12;
>   b)  b1 is true because abs(6) <= abs(12);
>   c)  b1 is true because 12 is an integer multiple of 6;
>   d)  b1 is true because the binary representation of 6 appears in the
> binary representation of 12;
>   e)  b1 is true because x=y is true (using redefined "=");
>   f)   b1 is false because x=y is false (using standard."=");
>   g)  b2 is false because 6 is not in the set containing only the
> number 12;
>   h)  the program is illegal because of b1;
>   i)   the program is illegal because of b2.

Nice quiz... I'll post my answers later, to allow others to think some
more about it... or maybe all interested people should reply to you
privately? would you publish the results later? :)

--
Ludovic Brenta.



^ permalink raw reply	[relevance 0%]

* Re: extended membership tests
  2011-03-31  7:55  0%   ` Dan
@ 2011-03-31  7:58  0%     ` Dan
  0 siblings, 0 replies; 53+ results
From: Dan @ 2011-03-31  7:58 UTC (permalink / raw)


On Mar 31, 12:55 am, Dan <d...@irvine.com> wrote:
> On Mar 31, 12:34 am, AdaMagica <christ-usch.gr...@t-online.de> wrote:
>
>
>
>
>
> > On 31 Mrz., 09:04, Dan <d...@irvine.com> wrote:
>
> > > Here's a fun quiz to test your Ada2012 knowledge, based on an
> > > observation by Yannick Moy.
>
> > > Consider this Ada 2012 procedure:
>
> > > with ada.containers.ordered_sets;
> > > procedure membership is
> > >     package int_sets is new ada.containers.ordered_sets(integer);
> > >     function "="(x,y: integer) return boolean is begin return true;
> > > end;
> > >     x: integer := 6;
> > >     y: integer := 12;
> > >     b1: boolean := x in y;
> > >     b2: boolean := x in int_sets.to_set(new_item => y);
> > > begin
> > >     null;
> > > end;
>
> > My first reaction was WTF!
>
> > But RM 4.5.2 seems to make x in y legal, but false here.
>
> > x in y | 1..7
>
> > would be true.
>
> > b2 is illegal, the simple expression must be of an elementary type.
>
> > Hope this is correct.- Hide quoted text -
>
> > - Show quoted text -
>
> I think if the choice(s) resolve to the same type they don't have to
> be elementary,
> according to 4.5.2(3/3).  (other than that, good answer!)- Hide quoted text -
>
> - Show quoted text -

but you are right, they don't the lhs doesn't resolve to the same type
as the rhs,
so in this case the rhs does need to be elementary.



^ permalink raw reply	[relevance 0%]

* Re: extended membership tests
  2011-03-31  7:34  0% ` AdaMagica
@ 2011-03-31  7:55  0%   ` Dan
  2011-03-31  7:58  0%     ` Dan
  0 siblings, 1 reply; 53+ results
From: Dan @ 2011-03-31  7:55 UTC (permalink / raw)


On Mar 31, 12:34 am, AdaMagica <christ-usch.gr...@t-online.de> wrote:
> On 31 Mrz., 09:04, Dan <d...@irvine.com> wrote:
>
>
>
>
>
> > Here's a fun quiz to test your Ada2012 knowledge, based on an
> > observation by Yannick Moy.
>
> > Consider this Ada 2012 procedure:
>
> > with ada.containers.ordered_sets;
> > procedure membership is
> >     package int_sets is new ada.containers.ordered_sets(integer);
> >     function "="(x,y: integer) return boolean is begin return true;
> > end;
> >     x: integer := 6;
> >     y: integer := 12;
> >     b1: boolean := x in y;
> >     b2: boolean := x in int_sets.to_set(new_item => y);
> > begin
> >     null;
> > end;
>
> My first reaction was WTF!
>
> But RM 4.5.2 seems to make x in y legal, but false here.
>
> x in y | 1..7
>
> would be true.
>
> b2 is illegal, the simple expression must be of an elementary type.
>
> Hope this is correct.- Hide quoted text -
>
> - Show quoted text -

I think if the choice(s) resolve to the same type they don't have to
be elementary,
according to 4.5.2(3/3).  (other than that, good answer!)




^ permalink raw reply	[relevance 0%]

* Re: extended membership tests
  2011-03-31  7:04  5% extended membership tests Dan
@ 2011-03-31  7:34  0% ` AdaMagica
  2011-03-31  7:55  0%   ` Dan
  2011-03-31  8:05  0% ` Ludovic Brenta
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 53+ results
From: AdaMagica @ 2011-03-31  7:34 UTC (permalink / raw)


On 31 Mrz., 09:04, Dan <d...@irvine.com> wrote:
> Here's a fun quiz to test your Ada2012 knowledge, based on an
> observation by Yannick Moy.
>
> Consider this Ada 2012 procedure:
>
> with ada.containers.ordered_sets;
> procedure membership is
>     package int_sets is new ada.containers.ordered_sets(integer);
>     function "="(x,y: integer) return boolean is begin return true;
> end;
>     x: integer := 6;
>     y: integer := 12;
>     b1: boolean := x in y;
>     b2: boolean := x in int_sets.to_set(new_item => y);
> begin
>     null;
> end;

My first reaction was WTF!

But RM 4.5.2 seems to make x in y legal, but false here.

x in y | 1..7

would be true.

b2 is illegal, the simple expression must be of an elementary type.

Hope this is correct.



^ permalink raw reply	[relevance 0%]

* extended membership tests
@ 2011-03-31  7:04  5% Dan
  2011-03-31  7:34  0% ` AdaMagica
                   ` (3 more replies)
  0 siblings, 4 replies; 53+ results
From: Dan @ 2011-03-31  7:04 UTC (permalink / raw)


Here's a fun quiz to test your Ada2012 knowledge, based on an
observation by Yannick Moy.

Consider this Ada 2012 procedure:

with ada.containers.ordered_sets;
procedure membership is
    package int_sets is new ada.containers.ordered_sets(integer);
    function "="(x,y: integer) return boolean is begin return true;
end;
    x: integer := 6;
    y: integer := 12;
    b1: boolean := x in y;
    b2: boolean := x in int_sets.to_set(new_item => y);
begin
    null;
end;

Which of the following are true:
  a)  b1 is true because 6 <= 12;
  b)  b1 is true because abs(6) <= abs(12);
  c)  b1 is true because 12 is an integer multiple of 6;
  d)  b1 is true because the binary representation of 6 appears in the
binary representation of 12;
  e)  b1 is true because x=y is true (using redefined "=");
  f)   b1 is false because x=y is false (using standard."=");
  g)  b2 is false because 6 is not in the set containing only the
number 12;
  h)  the program is illegal because of b1;
  i)   the program is illegal because of b2.



^ permalink raw reply	[relevance 5%]

* Re: Breaking a circularity
  2011-03-28  4:11  3% Breaking a circularity Gene
  2011-03-28  9:59  4% ` Ludovic Brenta
@ 2011-03-28 11:06  4% ` Martin
  1 sibling, 0 replies; 53+ results
From: Martin @ 2011-03-28 11:06 UTC (permalink / raw)


On Mar 28, 5:11 am, Gene <gene.ress...@gmail.com> wrote:
> Need some expert help here with a circularity in the data structures
> for a discrete event simulation.
>
> We need event queues and an arbitrary number of event types.  The
> handlers for events must have access to a simulation state record, so
> used a generic thus:
>
> generic
>    type State_Type is private;
> package Event_Queues is
>
>    type Event_Type is abstract tagged limited private;
>
>    procedure Handle(State : in out State_Type;
>                     Event : access Event_Type) is abstract;
>
>    type Event_Ptr_Type is access all Event_Type'Class;
>
>    procedure Add(Event_Queue : in out Event_Queue_Type;
>                  Time : in Time_Type;
>                  Event : access Event_Type'Class);
>
>    -- other methods not shown.
> private
>
>    type Event_Type is abstract record
>       Id : Positive;
>       Time : Time_Type;
>    end record;
>
>    function Sooner_Than(A, B : in Event_Ptr_Type) return Boolean;
>
>    -- We are just going to put a thin wrapper around Ada ordered sets
> to
>    -- implement our event queue.
>    package Event_Queues is
>      new Ada.Containers.Ordered_Sets(Event_Ptr_Type, Sooner_Than,
> "=");
>    type Event_Queue_Type is new Event_Queues.Set with null record;
>
> end Event_Queues;
>
> Here's the circularity:  Instantiating an event queue requires the
> simulation state type, but the simulation state must contain an event
> queue (of the instantiated type).
>
> This is the best I've come up with so far:
>
> private
>    type Event_Queue_Wrapper_Type;
>
>    type State_Type is
>       record
>          Future_Events : access Event_Queue_Wrapper_Type;
>          -- other stuff not shown
>       end record;
>
>    package Simulation_Events is
>      new Event_Queues(State_Type);
>
>    -- Now we can define the wrapper to contain the event queue.
>    type Event_Queue_Wrapper_Type is
>       record
>          Queue : Simulation_Events.Event_Queue_Type;
>       end record;
>
> Is there a cleaner way to do this?  The painful part is introducing a
> pointer to the event queue in State_Type just to break the
> circularity, when this seems superfluous and means I should make
> State_Type controlled to release the queue.


Not sure you can do better in the sense of removing the access but
perhaps you can bundle all that up into a generic wrapper? e.g.

package States is
   type State is record
      I : Integer;
   end record;
end States;

with Ada.Containers.Ordered_Sets;
generic
   type State_Type is private;
package Event_Queues is
   subtype Time_Type is Duration;
   type Event_Type is abstract tagged limited private;
   procedure Handle (State : in out State_Type;
                     Event : access Event_Type) is abstract;
   type Event_Ptr_Type is access all Event_Type'Class;
   type Event_Queue_Type is private;
   procedure Add (Event_Queue : in out Event_Queue_Type;
                  Time        : in     Time_Type;
                  Event       : access Event_Type'Class);
private
   type Event_Type is abstract tagged limited record
      Id   : Positive;
      Time : Time_Type;
   end record;
   function Sooner_Than (A, B : in Event_Ptr_Type) return Boolean;
   package Event_Queues is new Ada.Containers.Ordered_Sets
(Event_Ptr_Type, Sooner_Than, "=");
   type Event_Queue_Type is new Event_Queues.Set with null record;
end Event_Queues;

with Event_Queues;
generic
   type State_Type is private;
package Event_Queue_Wrappers is
   type Event_Queue_Wrapper_Type is private;
private
   type EQW_State_Type is
      record
         State         : State_Type;
         Future_Events : access Event_Queue_Wrapper_Type;
      end record;
   package Simulation_Events is new Event_Queues (EQW_State_Type);
   type Event_Queue_Wrapper_Type is record
         Queue : Simulation_Events.Event_Queue_Type;
      end record;
end Event_Queue_Wrappers;

with Event_Queue_Wrappers;
with States;

procedure Temp is
   package EQW is new Event_Queue_Wrappers (State_Type =>
States.State);
   EQ : EQW.Event_Queue_Wrapper_Type;
begin
   null;
end Temp;


At least that decouples the state your interested in from the queue
mechanism.

Better names might help too, why expose that it is a 'wrapper' to the
user? I'd probably call what I have a '_Wrapper' as 'Event_Queue' and
then find a better name for the Event_Queues - Event_Queues_With_State
perhaps.

-- Martin



^ permalink raw reply	[relevance 4%]

* Re: Breaking a circularity
  2011-03-28  4:11  3% Breaking a circularity Gene
@ 2011-03-28  9:59  4% ` Ludovic Brenta
  2011-03-28 11:06  4% ` Martin
  1 sibling, 0 replies; 53+ results
From: Ludovic Brenta @ 2011-03-28  9:59 UTC (permalink / raw)


Gene wrote on comp.lang.ada:
> Need some expert help here with a circularity in the data structures
> for a discrete event simulation.
>
> We need event queues and an arbitrary number of event types.  The
> handlers for events must have access to a simulation state record, so
> used a generic thus:
[...]
> Here's the circularity:  Instantiating an event queue requires the
> simulation state type, but the simulation state must contain an event
> queue (of the instantiated type).
[...]
> Is there a cleaner way to do this?  The painful part is introducing a
> pointer to the event queue in State_Type just to break the
> circularity, when this seems superfluous and means I should make
> State_Type controlled to release the queue.

How about this:

generic
   type State_Type is tagged private;
package States_With_Event_Queues is

   type State_With_Event_Queue_Type is new State_Type with private;

   type Event_Type is abstract tagged limited private;

   procedure Handle(State : in out State_Type;
                    Event : access Event_Type) is abstract;

   type Event_Ptr_Type is access all Event_Type'Class;

   procedure Add(Event_Queue : in out Event_Queue_Type;
                 Time : in Time_Type;
                 Event : access Event_Type'Class);

   -- other methods not shown.
private

   type Event_Type is abstract record
      Id : Positive;
      Time : Time_Type;
   end record;

   function Sooner_Than(A, B : in Event_Ptr_Type) return Boolean;

   -- We are just going to put a thin wrapper around Ada ordered sets
   -- to implement our event queue.
   package Event_Queues is
     new Ada.Containers.Ordered_Sets(Event_Ptr_Type, Sooner_Than,
"=");
   type Event_Queue_Type is new Event_Queues.Set with null record;

   type State_With_Event_Queue_Type is new State_Type with record
      Event_Queue : Event_Queue_Type;
   end record;

end States_With_event_Queues;



Would that work?

BTW, why does Event_Type have to be limited? If it weren't limited,
you would not need Event_Ptr_Type.  Also, why does it have to be
abstract?

--
Ludovic Brenta.



^ permalink raw reply	[relevance 4%]

* Breaking a circularity
@ 2011-03-28  4:11  3% Gene
  2011-03-28  9:59  4% ` Ludovic Brenta
  2011-03-28 11:06  4% ` Martin
  0 siblings, 2 replies; 53+ results
From: Gene @ 2011-03-28  4:11 UTC (permalink / raw)


Need some expert help here with a circularity in the data structures
for a discrete event simulation.

We need event queues and an arbitrary number of event types.  The
handlers for events must have access to a simulation state record, so
used a generic thus:

generic
   type State_Type is private;
package Event_Queues is

   type Event_Type is abstract tagged limited private;

   procedure Handle(State : in out State_Type;
                    Event : access Event_Type) is abstract;

   type Event_Ptr_Type is access all Event_Type'Class;

   procedure Add(Event_Queue : in out Event_Queue_Type;
                 Time : in Time_Type;
                 Event : access Event_Type'Class);

   -- other methods not shown.
private

   type Event_Type is abstract record
      Id : Positive;
      Time : Time_Type;
   end record;

   function Sooner_Than(A, B : in Event_Ptr_Type) return Boolean;

   -- We are just going to put a thin wrapper around Ada ordered sets
to
   -- implement our event queue.
   package Event_Queues is
     new Ada.Containers.Ordered_Sets(Event_Ptr_Type, Sooner_Than,
"=");
   type Event_Queue_Type is new Event_Queues.Set with null record;

end Event_Queues;

Here's the circularity:  Instantiating an event queue requires the
simulation state type, but the simulation state must contain an event
queue (of the instantiated type).

This is the best I've come up with so far:

private
   type Event_Queue_Wrapper_Type;

   type State_Type is
      record
         Future_Events : access Event_Queue_Wrapper_Type;
         -- other stuff not shown
      end record;

   package Simulation_Events is
     new Event_Queues(State_Type);

   -- Now we can define the wrapper to contain the event queue.
   type Event_Queue_Wrapper_Type is
      record
         Queue : Simulation_Events.Event_Queue_Type;
      end record;

Is there a cleaner way to do this?  The painful part is introducing a
pointer to the event queue in State_Type just to break the
circularity, when this seems superfluous and means I should make
State_Type controlled to release the queue.



^ permalink raw reply	[relevance 3%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-28 11:36  5%     ` Stephen Leake
@ 2010-09-29  1:25  0%       ` Gene
  0 siblings, 0 replies; 53+ results
From: Gene @ 2010-09-29  1:25 UTC (permalink / raw)


On Sep 28, 7:36 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> Gene <gene.ress...@gmail.com> writes:
> > Thanks.  This is one variation I tried.  There is first a compiler
> > complaint that this private subtype declaration doesn't match the
> > earlier public "type Queue is private".  I take it there is no way at
> > all to declare a type private and then specify it in the private
> > section as a subtype?
>
> Ah; I had not realized the original problem you were having; how to
> implement the body for Is_Empty. The simplest approach is this:
>
> with Ada.Containers.Ordered_Sets;
> package Foo is
>   type Queue is private;
>   procedure Add(Q : in out Queue; Item : in Integer);
>   function Is_Empty(Q : Queue) return Boolean;
> private
>   package Queues is
>     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
>   type Queue is new Queues.Set with null record;
> end Foo;
> package body Foo is
>    procedure Add(Q : in out Queue; Item : in Integer)
>       renames Insert;
>
>    function Is_Empty(Q : Queue) return Boolean
>    is begin
>       return Queues.Is_Empty (Queues.Set (Q));
>    end Is_Empty;
> end Foo;
>
> --
> -- Stephe

Right.  Thanks. Understood that from the outset. Was just scratching
my head because Insert could be defined by renaming, but there was no
way to do the same for Is_Empty owing to the name clash.  I thought
there had to be some dot-path that would work.  In fact the only
recourses (using renaming) seem to be either to choose another name
for the public Is_Empty or to use the ingenous but truly crufty double
renaming trick shown by Adam Beneschan.

FWIW, I'm working out a framework for a student project, so the desire
for symmetry in the code is more pedantic than esthetic or anything
else.

Thanks guys.




^ permalink raw reply	[relevance 0%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-27  1:18  0%   ` Gene
@ 2010-09-28 11:36  5%     ` Stephen Leake
  2010-09-29  1:25  0%       ` Gene
  0 siblings, 1 reply; 53+ results
From: Stephen Leake @ 2010-09-28 11:36 UTC (permalink / raw)


Gene <gene.ressler@gmail.com> writes:

> Thanks.  This is one variation I tried.  There is first a compiler
> complaint that this private subtype declaration doesn't match the
> earlier public "type Queue is private".  I take it there is no way at
> all to declare a type private and then specify it in the private
> section as a subtype?

Ah; I had not realized the original problem you were having; how to
implement the body for Is_Empty. The simplest approach is this:

with Ada.Containers.Ordered_Sets;
package Foo is
  type Queue is private;
  procedure Add(Q : in out Queue; Item : in Integer);
  function Is_Empty(Q : Queue) return Boolean;
private
  package Queues is
    new Ada.Containers.Ordered_Sets(Integer, "<", "=");
  type Queue is new Queues.Set with null record;
end Foo;
package body Foo is
   procedure Add(Q : in out Queue; Item : in Integer)
      renames Insert;

   function Is_Empty(Q : Queue) return Boolean
   is begin
      return Queues.Is_Empty (Queues.Set (Q));
   end Is_Empty;
end Foo;

-- 
-- Stephe



^ permalink raw reply	[relevance 5%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  0:43  6% Renaming of procedures in a generic instantiation Gene
  2010-09-26  6:54  0% ` Niklas Holsti
  2010-09-26  8:45  0% ` Stephen Leake
@ 2010-09-27 19:23  4% ` Adam Beneschan
  2 siblings, 0 replies; 53+ results
From: Adam Beneschan @ 2010-09-27 19:23 UTC (permalink / raw)


On Sep 25, 5:43 pm, Gene <gene.ress...@gmail.com> wrote:
> I'm confused about an aspect of renaming. It boils out to this little
> example:
>
> with Ada.Containers.Ordered_Sets;
>
> package Foo is
>
>   type Queue is private;
>
>   procedure Add(Q : in out Queue; Item : in Integer);
>
>   function Is_Empty(Q : Queue) return Boolean;
>
> private
>
>   package Queues is
>     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
>   type Queue is new Queues.Set with null record;
>
> end Foo;
>
> package body Foo is
>
>    procedure Add(Q : in out Queue; Item : in Integer)
>       renames Insert;
>
>    function Is_Empty(Q : Queue) return Boolean
>       renames Queues.Is_Empty;
>
> end Foo;
>
> The renaming in Add "finds" the correct procedure Insert, but the
> renaming of Is_Empty fails:
>
> gnatmake foo.adb
> gcc -c foo.adb
> foo.adb:6:04: no visible subprogram matches the specification for
> "Is_Empty"
> foo.adb:6:13: expected private type "Ada.Containers.Ordered_Sets.Set"
> from insta
> nce at foo.ads:14
> foo.adb:6:13: found type "Queue" defined at foo.ads:16
> gnatmake: "foo.adb" compilation error
>
> I guess I can see this error because a parameter type conversion is
> implied in the renaming.  But then why does the renaming of Insert
> work correctly?

Because you didn't refer to the "Insert" defined in Queues, the way
you did with Is_Empty.  If you had declared this, it would be illegal
in the same way:

   procedure Add(Q : in out Queue; Item : in Integer)
      renames Queues.Insert;

Obviously, you can't solve the problem for Is_Empty by removing the
"Queues." prefix:

   function Is_Empty(Q : in out Queue) return Boolean
      renames Is_Empty;

I found that this compiles, but it's obnoxious:

with Ada.Containers.Ordered_Sets;
package Foo is
  type Queue is private;
  procedure Add(Q : in out Queue; Item : in Integer);
  function Is_Empty(Q : Queue) return Boolean;
private
  package Queues is
    new Ada.Containers.Ordered_Sets(Integer, "<", "=");
  package Dummy_Package is
    type Dummy_Queue is new Queues.Set with null record;
    function Rename_Empty(Q : Dummy_Queue) return Boolean
      renames Is_Empty;
  end Dummy_Package;
  type Queue is new Dummy_Package.Dummy_Queue with null record;
end Foo;

package body Foo is
   procedure Add(Q : in out Queue; Item : in Integer)
      renames Insert;

   function Is_Empty(Q : Queue) return Boolean
      renames Rename_Empty;
end Foo;

Just writing Is_Empty to call Queues.Is_Empty, as Niklas suggested,
seems better than this.  I'd also add "pragma Inline(Is_Empty)" to the
private part of Foo to possibly prevent extraneous call code from
being generated.

I had thought that someone (possibly me) once proposed adding the
ability to declare that a subprogram renames the hidden subprogram
that it overrides, e.g.

   function Is_Empty(Q : Queue) return Boolean renames <>;

but I can't find anything like that in my mail records.  Randy did
once mention using something like Is_Empty'Parent as a stand-in for
the call to the parent routine; he wasn't thinking of a renaming
context, but it might work here:

   function Is_Empty(Q : Queue) return Boolean renames
Is_Empty'Parent;

In any event, however, it seems to be a minor enough problem with a
simple enough workaround that it's not worthwhile to change the
language.

                            -- Adam









^ permalink raw reply	[relevance 4%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  8:45  0% ` Stephen Leake
  2010-09-26  9:11  0%   ` Niklas Holsti
@ 2010-09-27  1:18  0%   ` Gene
  2010-09-28 11:36  5%     ` Stephen Leake
  1 sibling, 1 reply; 53+ results
From: Gene @ 2010-09-27  1:18 UTC (permalink / raw)


On Sep 26, 4:45 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> Gene <gene.ress...@gmail.com> writes:
> > I'm confused about an aspect of renaming. It boils out to this little
> > example:
>
> > with Ada.Containers.Ordered_Sets;
>
> > package Foo is
>
> >   type Queue is private;
>
> >   procedure Add(Q : in out Queue; Item : in Integer);
>
> >   function Is_Empty(Q : Queue) return Boolean;
>
> > private
>
> >   package Queues is
> >     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
> >   type Queue is new Queues.Set with null record;
>
> All primitive operations of Queues.Set are implicitly declared here,
> with Queue replacing Queues.Set; that includes Set and Is_Empty. That's
> what derived types are for.
>
> > end Foo;
>
> > package body Foo is
>
> >    procedure Add(Q : in out Queue; Item : in Integer)
> >       renames Insert;
>
> This 'Insert' resolves to Foo.Insert (Container : in out Foo.Queue; ...);
>
> >    function Is_Empty(Q : Queue) return Boolean
> >       renames Queues.Is_Empty;
>
> Queues.Is_Empty expects a Constainer of type Foo.Queues.Set, not Foo.Queue.
>
> If you replace
>
>    type Queue is new Queues.Set with null record;
>
> with
>
>    subtype Queue is Queues.Set;
>
> Then the Add renames will fail (because the primitive operations are not
> derived), and the Is_Empty will succeed.
>
> --
> -- Stephe- Hide quoted text -
>
> - Show quoted text -

Thanks.  This is one variation I tried.  There is first a compiler
complaint that this private subtype declaration doesn't match the
earlier public "type Queue is private".  I take it there is no way at
all to declare a type private and then specify it in the private
section as a subtype?



^ permalink raw reply	[relevance 0%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  6:54  0% ` Niklas Holsti
@ 2010-09-26 14:52  0%   ` Gene
  0 siblings, 0 replies; 53+ results
From: Gene @ 2010-09-26 14:52 UTC (permalink / raw)


On Sep 26, 2:54 am, Niklas Holsti <niklas.hol...@tidorum.invalid>
wrote:
> Gene wrote:
> > I'm confused about an aspect of renaming. It boils out to this little
> > example:
>
> > with Ada.Containers.Ordered_Sets;
>
> > package Foo is
>
> >   type Queue is private;
>
> >   procedure Add(Q : in out Queue; Item : in Integer);
>
> >   function Is_Empty(Q : Queue) return Boolean;
>
> > private
>
> >   package Queues is
> >     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
> >   type Queue is new Queues.Set with null record;
>
> > end Foo;
>
> > package body Foo is
>
> >    procedure Add(Q : in out Queue; Item : in Integer)
> >       renames Insert;
>
> >    function Is_Empty(Q : Queue) return Boolean
> >       renames Queues.Is_Empty;
>
> > end Foo;
>
> > The renaming in Add "finds" the correct procedure Insert, but the
> > renaming of Is_Empty fails:
>
> > gnatmake foo.adb
> > gcc -c foo.adb
> > foo.adb:6:04: no visible subprogram matches the specification for
> > "Is_Empty"
> > foo.adb:6:13: expected private type "Ada.Containers.Ordered_Sets.Set"
> > from insta
> > nce at foo.ads:14
> > foo.adb:6:13: found type "Queue" defined at foo.ads:16
> > gnatmake: "foo.adb" compilation error
>
> > I guess I can see this error because a parameter type conversion is
> > implied in the renaming.  But then why does the renaming of Insert
> > work correctly?
>
> The type derivation
>
>    type Queue is new Queues.Set with null record;
>
> makes type Queue inherit the primitive operations of Queues.Set by
> implicitly declaring (within package Foo) corresponding operations on
> type Queue. These include the operation Insert with the profile:
>
>     procedure Insert (
>        Container : in out Queue;
>        New_Item  : in     Integer);
>
> This profile matches that of Foo.Add, and so Foo.Add can be a renaming
> of this Insert. By the way, this implicitly declared Insert (on Queue)
> has the qualified name Foo.Insert, not Queues.Insert.
>
> The type derivation also "tries" to declare implicitly the Is_Empty
> operation from Queues, with the profile:
>
>     function Is_Empty (Container : Queue) return Boolean;
>
> but this operation clashes with (has the same name and same profile as)
> the operation Is_Empty that was already and explicitly declared in Foo
> (before the "private"), so they cannot both be visible. If I understand
> correctly, the rule RM 8.3(10/1) says that the first, explicit
> declaration overrides the second, implicit declaration (because the
> first declaration is not "overridable").
>
> So what saves you in the Insert/Add case is that the operation names are
> different, which means there is no clash. It is a bit irritating that
> the "simpler" case, with the same names, does not work in the same way.
>
> I have at times had the same problem, where I have been disappointed
> that implementing a private type as a derived type does not implicitly
> complete the declarations of matching operations, such as Is_Empty in
> this example. I would have liked to be able to write something like:
>
>     type Queue is new Queues.Set with null record
>        overriding Is_Empty (Q : Queue) return Boolean;  -- Not Ada!
>
> No doubt you have already found a solution for Is_Empty, but anyway here
> is what I would do:
>
>     function Is_Empty (Q : Queue) return Boolean
>     is
>     begin
>        return Queues.Is_Empty (Queues.Set (Q));
>     end Is_Empty;
>
> --
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
>        .      @       .- Hide quoted text -

Thanks for the clear and quick explanation.  It makes sense, but, as
you say, is a bit unsatisfying.  I've run into several cases where I
want to implement an abstraction with minor reshaping and restriction
of an Ada.Containers instance.  (The current one is event queues for a
simulator.)  As you've shown above, there are some quirks in this
approach.




^ permalink raw reply	[relevance 0%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  8:45  0% ` Stephen Leake
@ 2010-09-26  9:11  0%   ` Niklas Holsti
  2010-09-27  1:18  0%   ` Gene
  1 sibling, 0 replies; 53+ results
From: Niklas Holsti @ 2010-09-26  9:11 UTC (permalink / raw)


Stephen Leake wrote:
> Gene <gene.ressler@gmail.com> writes:
> 
>> I'm confused about an aspect of renaming. It boils out to this little
>> example:
>>
>> with Ada.Containers.Ordered_Sets;
>>
>> package Foo is
>>
>>   type Queue is private;
>>
>>   procedure Add(Q : in out Queue; Item : in Integer);
>>
>>   function Is_Empty(Q : Queue) return Boolean;
>>
>> private
>>
>>   package Queues is
>>     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
>>   type Queue is new Queues.Set with null record;
> 
> All primitive operations of Queues.Set are implicitly declared here,
> with Queue replacing Queues.Set; that includes Set and Is_Empty. That's
> what derived types are for.
> 
>> end Foo;
>>
>> package body Foo is
>>
>>    procedure Add(Q : in out Queue; Item : in Integer)
>>       renames Insert;
> 
> This 'Insert' resolves to Foo.Insert (Container : in out Foo.Queue; ...);
> 
>>    function Is_Empty(Q : Queue) return Boolean
>>       renames Queues.Is_Empty;
> 
> Queues.Is_Empty expects a Constainer of type Foo.Queues.Set, not Foo.Queue.
> 
> If you replace 
> 
>    type Queue is new Queues.Set with null record;
> 
> with 
> 
>    subtype Queue is Queues.Set;
> 
> Then the Add renames will fail (because the primitive operations are not
> derived), and the Is_Empty will succeed.

But the subtype declaration of Queue cannot complete the initial 
declaration of Queue as private, so the subtype declaration must be the 
first and only (and public) declaration of type Queue.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[relevance 0%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  0:43  6% Renaming of procedures in a generic instantiation Gene
  2010-09-26  6:54  0% ` Niklas Holsti
@ 2010-09-26  8:45  0% ` Stephen Leake
  2010-09-26  9:11  0%   ` Niklas Holsti
  2010-09-27  1:18  0%   ` Gene
  2010-09-27 19:23  4% ` Adam Beneschan
  2 siblings, 2 replies; 53+ results
From: Stephen Leake @ 2010-09-26  8:45 UTC (permalink / raw)


Gene <gene.ressler@gmail.com> writes:

> I'm confused about an aspect of renaming. It boils out to this little
> example:
>
> with Ada.Containers.Ordered_Sets;
>
> package Foo is
>
>   type Queue is private;
>
>   procedure Add(Q : in out Queue; Item : in Integer);
>
>   function Is_Empty(Q : Queue) return Boolean;
>
> private
>
>   package Queues is
>     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
>   type Queue is new Queues.Set with null record;

All primitive operations of Queues.Set are implicitly declared here,
with Queue replacing Queues.Set; that includes Set and Is_Empty. That's
what derived types are for.

> end Foo;
>
> package body Foo is
>
>    procedure Add(Q : in out Queue; Item : in Integer)
>       renames Insert;

This 'Insert' resolves to Foo.Insert (Container : in out Foo.Queue; ...);

>    function Is_Empty(Q : Queue) return Boolean
>       renames Queues.Is_Empty;

Queues.Is_Empty expects a Constainer of type Foo.Queues.Set, not Foo.Queue.

If you replace 

   type Queue is new Queues.Set with null record;

with 

   subtype Queue is Queues.Set;

Then the Add renames will fail (because the primitive operations are not
derived), and the Is_Empty will succeed.

-- 
-- Stephe



^ permalink raw reply	[relevance 0%]

* Re: Renaming of procedures in a generic instantiation
  2010-09-26  0:43  6% Renaming of procedures in a generic instantiation Gene
@ 2010-09-26  6:54  0% ` Niklas Holsti
  2010-09-26 14:52  0%   ` Gene
  2010-09-26  8:45  0% ` Stephen Leake
  2010-09-27 19:23  4% ` Adam Beneschan
  2 siblings, 1 reply; 53+ results
From: Niklas Holsti @ 2010-09-26  6:54 UTC (permalink / raw)


Gene wrote:
> I'm confused about an aspect of renaming. It boils out to this little
> example:
> 
> with Ada.Containers.Ordered_Sets;
> 
> package Foo is
> 
>   type Queue is private;
> 
>   procedure Add(Q : in out Queue; Item : in Integer);
> 
>   function Is_Empty(Q : Queue) return Boolean;
> 
> private
> 
>   package Queues is
>     new Ada.Containers.Ordered_Sets(Integer, "<", "=");
>   type Queue is new Queues.Set with null record;
> 
> end Foo;
> 
> package body Foo is
> 
>    procedure Add(Q : in out Queue; Item : in Integer)
>       renames Insert;
> 
>    function Is_Empty(Q : Queue) return Boolean
>       renames Queues.Is_Empty;
> 
> end Foo;
> 
> The renaming in Add "finds" the correct procedure Insert, but the
> renaming of Is_Empty fails:
> 
> gnatmake foo.adb
> gcc -c foo.adb
> foo.adb:6:04: no visible subprogram matches the specification for
> "Is_Empty"
> foo.adb:6:13: expected private type "Ada.Containers.Ordered_Sets.Set"
> from insta
> nce at foo.ads:14
> foo.adb:6:13: found type "Queue" defined at foo.ads:16
> gnatmake: "foo.adb" compilation error
> 
> I guess I can see this error because a parameter type conversion is
> implied in the renaming.  But then why does the renaming of Insert
> work correctly?

The type derivation

   type Queue is new Queues.Set with null record;

makes type Queue inherit the primitive operations of Queues.Set by 
implicitly declaring (within package Foo) corresponding operations on 
type Queue. These include the operation Insert with the profile:

    procedure Insert (
       Container : in out Queue;
       New_Item  : in     Integer);

This profile matches that of Foo.Add, and so Foo.Add can be a renaming 
of this Insert. By the way, this implicitly declared Insert (on Queue) 
has the qualified name Foo.Insert, not Queues.Insert.

The type derivation also "tries" to declare implicitly the Is_Empty 
operation from Queues, with the profile:

    function Is_Empty (Container : Queue) return Boolean;

but this operation clashes with (has the same name and same profile as) 
the operation Is_Empty that was already and explicitly declared in Foo 
(before the "private"), so they cannot both be visible. If I understand 
correctly, the rule RM 8.3(10/1) says that the first, explicit 
declaration overrides the second, implicit declaration (because the 
first declaration is not "overridable").

So what saves you in the Insert/Add case is that the operation names are 
different, which means there is no clash. It is a bit irritating that 
the "simpler" case, with the same names, does not work in the same way.

I have at times had the same problem, where I have been disappointed 
that implementing a private type as a derived type does not implicitly 
complete the declarations of matching operations, such as Is_Empty in 
this example. I would have liked to be able to write something like:

    type Queue is new Queues.Set with null record
       overriding Is_Empty (Q : Queue) return Boolean;  -- Not Ada!

No doubt you have already found a solution for Is_Empty, but anyway here 
is what I would do:

    function Is_Empty (Q : Queue) return Boolean
    is
    begin
       return Queues.Is_Empty (Queues.Set (Q));
    end Is_Empty;

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



^ permalink raw reply	[relevance 0%]

* Renaming of procedures in a generic instantiation
@ 2010-09-26  0:43  6% Gene
  2010-09-26  6:54  0% ` Niklas Holsti
                   ` (2 more replies)
  0 siblings, 3 replies; 53+ results
From: Gene @ 2010-09-26  0:43 UTC (permalink / raw)


I'm confused about an aspect of renaming. It boils out to this little
example:

with Ada.Containers.Ordered_Sets;

package Foo is

  type Queue is private;

  procedure Add(Q : in out Queue; Item : in Integer);

  function Is_Empty(Q : Queue) return Boolean;

private

  package Queues is
    new Ada.Containers.Ordered_Sets(Integer, "<", "=");
  type Queue is new Queues.Set with null record;

end Foo;

package body Foo is

   procedure Add(Q : in out Queue; Item : in Integer)
      renames Insert;

   function Is_Empty(Q : Queue) return Boolean
      renames Queues.Is_Empty;

end Foo;

The renaming in Add "finds" the correct procedure Insert, but the
renaming of Is_Empty fails:

gnatmake foo.adb
gcc -c foo.adb
foo.adb:6:04: no visible subprogram matches the specification for
"Is_Empty"
foo.adb:6:13: expected private type "Ada.Containers.Ordered_Sets.Set"
from insta
nce at foo.ads:14
foo.adb:6:13: found type "Queue" defined at foo.ads:16
gnatmake: "foo.adb" compilation error

I guess I can see this error because a parameter type conversion is
implied in the renaming.  But then why does the renaming of Insert
work correctly?

Running Win7 64 bit with:
gcc (GCC) 4.3.4 20090511 for GNAT GPL 2009 (20090511)

Thanks.



^ permalink raw reply	[relevance 6%]

* Re: Hash table
  @ 2005-08-13 23:58  4% ` Matthew Heaney
  0 siblings, 0 replies; 53+ results
From: Matthew Heaney @ 2005-08-13 23:58 UTC (permalink / raw)


David Trudgett <wpower@zeta.org.au.nospamplease>  writes:

> I'm looking for a Free Software Ada95 container library, or in
> particular, a hash table (or associative list).

Ada 2005 will have both sets and maps.  You're asking specifically for a
hashed version, but keep in mind that an ordered container (having an
identical interface, but different time complexity) might satisfy your
needs just as well.

The hashed containers are:

ada.containers.hashed_sets
ada.containers.indefinite_hashed_sets
ada.containers.hashed_maps
ada.containers.indefinite_hashed_maps

The ordered forms are:

ada.containers.ordered_sets
ada.containers.indefinite_ordered_sets
ada.containers.ordered_maps
ada.containers.indefinite_ordered_maps


> I noticed that Ada 2005 may include a standard Ada.Containers library,
> but is there a working prototype of this available now?

Yes, there's a public reference implementation available here:

http://charles.tigris.org/

Follow the links to the CVS repository, to the ai302 subdirectory.  The
names use gnat run-time syntax, so you're looking for:

a-cohama.ad[sb]
a-cihama.ad[sb]
a-cohase.ad[sb]
a-cihase.ad[sb]

Note that these will only compile with an Ada 2005 compiler.  If you're
using the latest version of gnat, use the -gnat05 switch to compile them.

If you don't have an Ada 2005 compiler, then you can modify the sources
to your liking.  That will mean replacing an anonymous access subprogram
parameters with something else, typically a generic operation that
passes the subprogram as a generic formal.  For example, the procedure:

procedure Iterate
  (Container : in Map;
   Process   : not null access procedure (Position : Cursor));

should be re-written as:

generic
   with procedure Process (Position : Cursor);
procedure Generic_Iteration (Container : in Map);

(Note that replacing the anonymous access subprogram parameters with
named access parameters is probably not what you want, because of the
accessibility rules.  Hence the generic declaration above.)


> A bit of searching found the ASL (Ada Structured Library --
> http://sourceforge.net/projects/adasl), which hasn't had a new release
> since 2001 (which means it must be perfect ;-)). Should I use ASL, and
> if I do, will it be completely different from the proposed
> Ada.Containers standard?

I would try to use a reference implementation of the standard library,
modified as necessary to run under pure Ada 95.  I can help you make the
necessary modifications.

In general, we prefer that users use the standard library now, since
that helps us find bugs in the design of the library (early adopters
have been extremely helpful here), and in the actual implementation of
the library.


> I'm using Gnat (3.15p) on Debian Linux.

Do you have access to gcc 4.x?  The standard container library is
already bundled with the gcc 4 release.

-Matt



^ permalink raw reply	[relevance 4%]

* Re: How difficult is ada to learn?
  @ 2005-06-30 19:36  4%       ` Matthew Heaney
  0 siblings, 0 replies; 53+ results
From: Matthew Heaney @ 2005-06-30 19:36 UTC (permalink / raw)


Randy Brukardt wrote:
> 
>>type Integer_Array is array (Positive range <>) of Integer;
>>
>>function "+" (IA : Integer) return Integer_Sets.Set is
> 
> 
> What's the definition of "Integer_Sets.Set"? Shouldn't IA have type
> Integer_Array, rather than Integer?

Yes.  A slipe of the ... fingers.


> Presuming that Integer_Sets.Set has "or" and "and" operations.

Yes.  Integer_Sets is an instantiation of Ada.Containers.Ordered_Sets.



^ permalink raw reply	[relevance 4%]

* Re: How difficult is ada to learn?
  @ 2005-06-30 19:32  4%       ` Matthew Heaney
  0 siblings, 0 replies; 53+ results
From: Matthew Heaney @ 2005-06-30 19:32 UTC (permalink / raw)


Gene wrote:
> 
> You perfectly illustrated what I meant.  The overloaded plus
> constructor is quite idiomatic.

And the syntax for Pascal sets isn't idiomatic???  Anyway, we're 
comparing apples and oranges; see my post about Ada's built-in sets.

But even the new set container looks an awful lot like Pascal.  For 
example, the tutorial here:

http://www.geocities.com/SiliconValley/Park/3230/pas/pasl1010.html

gives these examples:

exclude(myday,Friday);
include(myday,Friday);

That's no different from:

declare
    myday : Day_Sets.Set;
begin
    ...
    Exclude (myday, Friday);
    Include (myday, Friday);
end;

Again, Ada's choice of names here is quite deliberate.

If you're a teacher, it wouldn't take any effort to provide a helper 
package for your students, something like:

with Ada.Containers.Ordered_Sets;
generic
    with package Sets is new Ada.Containers.Ordered_Sets (<>);
    use Sets;
package Generic_Set_Arrays is
    type Element_Array is
      array (Positive range <>) of Sets.Element_Type;

    function To_Set (Element : Sets.Element_Type) return Set;
    function To_Set (Elements : Element_Array) return Set;
    function "+" (E : EA) return Set renames To_Set;

    function "and" (L : Set; R : EA) return Set;
    function "or" (L : Set; R : EA) return Set;
    ...

    function "and" (L, R : EA) return Set;
    function "or" (L, R : ET) return Set;
    ...
end Generic_Set_Arrays;

Given overloadings like these, it's not even necessary to use the "+" 
conversion operator:

declare
    S1 : Set := To_Set (1);
    S2 : Set := S1 and (2, 3, 4);
    S3 : Set := S2 or (4, 5);
    S4 : Set := (6, 7) and (7, 8);
begin ...

I can't imagine students who are struggling with the syntax for Ada sets 
to have an easier go of it in similar languages as C++, Java, etc, which 
are also taught in contemporary CS curricula.

Yes, Pascal has slightly more built-in support for sets than Ada does 
(i.e. syntax for a set literal), but sooner or later students will have 
a need for a more sophisticated set, that can store more than elements 
of a discrete type with small range of values.  And eventually they'll 
need a map or a list, and then what will they do?



^ permalink raw reply	[relevance 4%]

* Re: [Ann] More Ada0Y packages for Ada95!
  2004-08-19  7:44  0%   ` Martin Dowie
@ 2004-08-19 15:18  0%     ` Jano
  0 siblings, 0 replies; 53+ results
From: Jano @ 2004-08-19 15:18 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@baesystems.com> wrote in message news:<41245906$1_1@baen1673807.greenlnk.net>...
> Jano wrote:
> > Sorry for resurrecting an old thread but I'm getting errors using this
> > package. I've made an instance of the Ada.Containers.Ordered_Sets and
> > in my first attempt to insert something I get:
> >
> > Exception: Exception name: PROGRAM_ERROR
> > Message: EXCEPTION_ACCESS_VIOLATION
> 
> I think you have an "old" copy - the version on the web site has a fix for
> this. I did say on the web page that there was a problem with Ordered_Sets
> and you've found it! :-)

Oh, thanks, I must have missed it :/ Downloading now, if I remain
silent it means that everything went ok :)

Thanks!



^ permalink raw reply	[relevance 0%]

* Re: [Ann] More Ada0Y packages for Ada95!
  2004-08-19  4:02  4% ` Jano
@ 2004-08-19  7:44  0%   ` Martin Dowie
  2004-08-19 15:18  0%     ` Jano
  0 siblings, 1 reply; 53+ results
From: Martin Dowie @ 2004-08-19  7:44 UTC (permalink / raw)


Jano wrote:
> Sorry for resurrecting an old thread but I'm getting errors using this
> package. I've made an instance of the Ada.Containers.Ordered_Sets and
> in my first attempt to insert something I get:
>
> Exception: Exception name: PROGRAM_ERROR
> Message: EXCEPTION_ACCESS_VIOLATION

I think you have an "old" copy - the version on the web site has a fix for
this. I did say on the web page that there was a problem with Ordered_Sets
and you've found it! :-)

Cheers

-- Martin






^ permalink raw reply	[relevance 0%]

* Re: [Ann] More Ada0Y packages for Ada95!
    @ 2004-08-19  4:02  4% ` Jano
  2004-08-19  7:44  0%   ` Martin Dowie
  1 sibling, 1 reply; 53+ results
From: Jano @ 2004-08-19  4:02 UTC (permalink / raw)


"Martin Dowie" <martin.dowie@btopenworld.com> wrote in message news:<ce3tv5$ahh$1@hercules.btinternet.com>...
> I've updated my web page to include the following implementations:

> 4) AI-302 - Ada.Containers.*

Sorry for resurrecting an old thread but I'm getting errors using this
package. I've made an instance of the Ada.Containers.Ordered_Sets and
in my first attempt to insert something I get:

Exception: Exception name: PROGRAM_ERROR
Message: EXCEPTION_ACCESS_VIOLATION

more precisely in this assignation:

   procedure Set_Left
     (Node : Node_Access;
      Left : Node_Access) is
   begin
      Node.Left := Left; -- <-- HERE IN a-coorse.adb line 108
   end Set_Left;

The simplest instantiation using Natural as set members fails as well.

Can someone reproduce it? Thanks in advance,

Alex.



^ permalink raw reply	[relevance 4%]

* Re: [Ann] More Ada0Y packages for Ada95!
  2004-07-31 19:15  5%   ` Martin Dowie
@ 2004-08-02  7:38  0%     ` Jano
  0 siblings, 0 replies; 53+ results
From: Jano @ 2004-08-02  7:38 UTC (permalink / raw)


Martin Dowie wrote:
> Martin Dowie wrote:
> 
>>>I've updated my web page to include the following implementations:
>>
>>An address mught have been handy! :-)
>>
>>http://www.martin.dowie.btinternet.co.uk/
> 
> 
> Now with fixed "Ada.Containers.Ordered_Sets".
> 
> Please note that "Ada.Containers.*" is different to the others on this page
> in that it is still not at "Amendment 200Y" status (it's also still being
> tested by Matt) but I think it is of sufficient interest to include.

Would you say it is already at a good level of reliability (say, on par 
of Charles)? I make frequent use of Charles and I'm thinking of 
migrating already. I'm very interested in the containers for indefinite 
types too (my principal urge to migrate).

Best regards,

Alex.



^ permalink raw reply	[relevance 0%]

* Re: [Ann] More Ada0Y packages for Ada95!
    @ 2004-07-31 19:15  5%   ` Martin Dowie
  2004-08-02  7:38  0%     ` Jano
  1 sibling, 1 reply; 53+ results
From: Martin Dowie @ 2004-07-31 19:15 UTC (permalink / raw)


Martin Dowie wrote:
>> I've updated my web page to include the following implementations:
>
> An address mught have been handy! :-)
>
> http://www.martin.dowie.btinternet.co.uk/

Now with fixed "Ada.Containers.Ordered_Sets".

Please note that "Ada.Containers.*" is different to the others on this page
in that it is still not at "Amendment 200Y" status (it's also still being
tested by Matt) but I think it is of sufficient interest to include.

Cheers

-- Martin





^ permalink raw reply	[relevance 5%]

* Re: [Ann] More Ada0Y packages for Ada95!
  @ 2004-07-31 17:08  4%       ` Martin Dowie
  0 siblings, 0 replies; 53+ results
From: Martin Dowie @ 2004-07-31 17:08 UTC (permalink / raw)


"Anh_Vo" <anh_vo@udlp.com> wrote in message
news:5a59d6a9.0407301150.348121a8@posting.google.com...
> "Martin Dowie" <martin.dowie@btopenworld.com> wrote in message
news:<ce8pjj$7an$1@titan.btinternet.com>...
> > Martin Dowie wrote:
> > >> I've updated my web page to include the following implementations:
> > >
> > > An address mught have been handy! :-)
> > >
> > > http://www.martin.dowie.btinternet.co.uk/
> >
> > Just added AI-286 Ada.Assertions
>
> It is a great effort you are putting in.

You more than welcome - Matt has just fixed the Ada.Containers.Ordered_Sets,
so look out for an update of that real soon. :-)


> I would like to make a suggestion regarding exception handler. It
> would be better to use Raise_Exception (E => Exception_Name'Identity,
> "useful message") than raise Exception_Name. In fact, it is extremely
> useful in debugging quickly where the problem comes from.

Do you mean the Ada.Assertions package? Or all the packages? If you mean the
Ada.Assertions package then they give you exactly what the AI requires. If
you
want a message then use the overloaded subprogram that has the "Message"
parameter.

For Ada.Directories.* I did add quite a few with messages and hopefully they
are helpful. I think the rest are pretty bare in the exception message
department
but I've got time(!) I'll go back and add some where I can.

Cheers

-- Martin





^ permalink raw reply	[relevance 4%]

Results 1-53 of 53 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2004-07-26 21:44     [Ann] More Ada0Y packages for Ada95! Martin Dowie
2004-07-27  5:59     ` Martin Dowie
2004-07-28 18:00       ` Martin Dowie
2004-07-30 19:50         ` Anh_Vo
2004-07-31 17:08  4%       ` Martin Dowie
2004-07-31 19:15  5%   ` Martin Dowie
2004-08-02  7:38  0%     ` Jano
2004-08-19  4:02  4% ` Jano
2004-08-19  7:44  0%   ` Martin Dowie
2004-08-19 15:18  0%     ` Jano
2005-06-30  0:44     How difficult is ada to learn? Sm704
2005-06-30 14:19     ` Gene
2005-06-30 14:34       ` Matthew Heaney
2005-06-30 18:38         ` Gene
2005-06-30 19:32  4%       ` Matthew Heaney
2005-06-30 18:59         ` Randy Brukardt
2005-06-30 19:36  4%       ` Matthew Heaney
2005-08-13  0:43     Hash table David Trudgett
2005-08-13 23:58  4% ` Matthew Heaney
2010-09-26  0:43  6% Renaming of procedures in a generic instantiation Gene
2010-09-26  6:54  0% ` Niklas Holsti
2010-09-26 14:52  0%   ` Gene
2010-09-26  8:45  0% ` Stephen Leake
2010-09-26  9:11  0%   ` Niklas Holsti
2010-09-27  1:18  0%   ` Gene
2010-09-28 11:36  5%     ` Stephen Leake
2010-09-29  1:25  0%       ` Gene
2010-09-27 19:23  4% ` Adam Beneschan
2011-03-28  4:11  3% Breaking a circularity Gene
2011-03-28  9:59  4% ` Ludovic Brenta
2011-03-28 11:06  4% ` Martin
2011-03-31  7:04  5% extended membership tests Dan
2011-03-31  7:34  0% ` AdaMagica
2011-03-31  7:55  0%   ` Dan
2011-03-31  7:58  0%     ` Dan
2011-03-31  8:05  0% ` Ludovic Brenta
2011-03-31  9:28  0% ` AdaMagica
2011-03-31 14:33  0% ` Robert A Duff
2013-11-19  5:57  7% Strange instantiation error with formal packages ytomino
2014-08-05 20:09     A bad counterintuitive behaviour of Ada about OO Victor Porton
2014-08-05 20:59     ` Dmitry A. Kazakov
2014-08-05 21:11       ` Victor Porton
2014-08-06  7:26         ` Dmitry A. Kazakov
2014-08-07  7:41           ` Maciej Sobczak
2014-08-07  8:58             ` J-P. Rosen
2014-08-07  9:40               ` Dmitry A. Kazakov
2014-08-07 11:17                 ` J-P. Rosen
2014-08-07 12:28                   ` Dmitry A. Kazakov
2014-08-07 13:34                     ` J-P. Rosen
2014-08-07 16:10                       ` Dmitry A. Kazakov
2014-08-08  7:45                         ` J-P. Rosen
2014-08-08  8:04                           ` Dmitry A. Kazakov
2014-08-08  8:55                             ` J-P. Rosen
2014-08-08  9:13                               ` Dmitry A. Kazakov
2014-08-08 10:01                                 ` J-P. Rosen
2014-08-08 10:53  4%                               ` Dmitry A. Kazakov
2014-08-08 10:56  0%                                 ` Victor Porton
2014-08-08 12:00  0%                                 ` J-P. Rosen
2014-08-08 13:11  0%                                   ` Dmitry A. Kazakov
2015-04-07 20:35     BDD package in Ada Vincent DIEMUNSCH
2015-04-08  6:38     ` Dmitry A. Kazakov
2015-04-08  7:44       ` Vincent DIEMUNSCH
2015-04-08 21:30  4%     ` Randy Brukardt
2015-04-26 16:51  5% Change in GCC 5.1.0 Simon Wright
2015-04-26 18:42  0% ` jan.de.kruyf
2016-09-21 22:05     New to Ada need help implementing Warshall's algorithm James Brewer
2016-09-23  4:31  5% ` Shark8
2016-09-23 14:54  0%   ` James Brewer
2017-05-06 12:18     raised PROGRAM_ERROR : XXXXXX finalize/adjust raised exception reinert
2017-05-06 14:08     ` Jeffrey R. Carter
2017-05-06 14:57  6%   ` reinert
2017-05-06 15:46  0%     ` Jeffrey R. Carter
2017-05-06 14:59  6%   ` reinert
2017-05-06 15:05  4%     ` Dmitry A. Kazakov
2017-05-08 15:53     Question about sets and expression reinert
2017-05-08 16:06     ` Robert Eachus
2017-05-08 17:03  5%   ` reinert
2017-05-08 17:04  5%   ` reinert
2017-05-08 19:00     ` Simon Wright
2017-05-09  3:58       ` reinert
2017-05-09  5:48  6%     ` reinert
2023-02-14  8:49  6% Use Ada.Containers.Vectors Generic_Sorting or Ada.Containers.Ordered_Sets ? reinert
2023-02-14  9:35  6% ` Jeffrey R.Carter
2023-02-14 10:46  6%   ` reinert
2023-02-14 18:48  6%     ` G.B.
2023-03-15 10:05  6% ` Marius Amado-Alves
2023-03-15 14:24  6% ` Brad Moore
2023-09-04  9:19     project euler 26 CSYH (QAQ)
2023-09-04 11:06     ` Niklas Holsti
2023-09-04 12:39       ` Dmitry A. Kazakov
2023-09-04 16:01         ` Ben Bacarisse
2023-09-04 19:20           ` Dmitry A. Kazakov
2023-09-04 20:18             ` Ben Bacarisse
2023-09-04 21:00               ` Dmitry A. Kazakov
2023-09-04 23:16                 ` Ben Bacarisse
2023-09-05  7:23                   ` Dmitry A. Kazakov
2023-09-05 15:18                     ` Ben Bacarisse
2023-09-05 17:08                       ` Dmitry A. Kazakov
2023-09-06  1:10                         ` Ben Bacarisse
2023-09-06  7:06                           ` Dmitry A. Kazakov
2023-09-06 15:16                             ` Ben Bacarisse
2023-09-06 15:54                               ` Dmitry A. Kazakov
2023-09-06 23:32                                 ` Ben Bacarisse
2023-09-07  9:02  4%                               ` Dmitry A. Kazakov
2023-09-08  1:32  0%                                 ` Ben Bacarisse

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