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: Ada and Unicode
  @ 2022-04-07  1:30  5%               ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2022-04-07  1:30 UTC (permalink / raw)


"J-P. Rosen" <rosen@adalog.fr> wrote in message 
news:t2knpr$s26$1@dont-email.me...
...
> It was felt that in practice, being too strict in separating the types 
> would make things more difficult, without any practical gain. This has 
> been discussed - you may not agree with the outcome, but it was not made 
> out of pure lazyness

The problem with that, of course, is that it sends the wrong message 
vis-a-vis strong typing and interfaces. If we abandon it at the first sign 
of trouble, they we are saying that it isn't really that important.

In this particular case, the reason really came down to practicality: if you 
want to do anything string-like with a UTF-8 string, making it a separate 
type becomes painful. It wouldn't work with anything in Ada.Strings, 
Ada.Text_IO, or Ada.Directories, even though most of the operations are 
fine. And there was no political will to replace all of those things with 
versions to use with proper universal strings.

Moreover, if you really want to do that, you have to hide much of the array 
behavior of the Universal string. For instance, you can't allow willy-nilly 
slicing or replacement: cutting a character representation in half or 
setting an illegal representation has to be prohibited (operations that 
would turn a valid string into an invalid string should always raise an 
exception). That means you can't (directly) use built-in indexing and 
slicing -- those have to go through some sort of functions. So you do pretty 
much have to use a private type for universal strings (similar to 
Ada.Strings.Bounded would be best, I think).

If you had an Ada-like language that used a universal UTF-8 string 
internally, you then would have a lot of old and mostly useless operations 
supported for array types (since things like slices are mainly useful for 
string operations). So such a language should simplify the core 
substantially by dropping many of those obsolete features (especially as 
little of the library would be directly compatible anyway). So one should 
end up with a new language that draws from Ada rather than something in Ada 
itself. (It would be great if that language could make strings with 
different capacities interoperable - a major annoyance with Ada. And 
modernizing access types, generalizing resolution, and the like also would 
be good improvements IMHO.)

                                               Randy.


^ permalink raw reply	[relevance 5%]

* Re: Empty String confusion; Positive and Natural
    2021-11-30  8:29  5%     ` Simon Wright
@ 2021-11-30  8:34  5%     ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Niklas Holsti @ 2021-11-30  8:34 UTC (permalink / raw)


On 2021-11-30 0:50, Kevin Chadwick wrote:
>> It would clarify your question if you would show the declaration of that
>> record type. Does it use the String type, or the Unbounded_String type?
> 
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String

Although Standard.String is an unconstrained array type (that is, its 
index range is defined as "Positive range <>"), every object of this 
type is constrained to a fixed length, set when the object is created.

So if you have, for example:

    S : String (1 .. 10);

then S'Length is always 10. If you try to assign to S a string of a 
different length, for example "", you will get an exception because the 
lengths do not match.

If you want a string object that is flexible in terms of length, you 
should use the type Ada.Strings.Unbounded.Unbounded_String, or make an 
instance of Ada.Strings.Bounded.Bounded_String with a suitable maximum 
length.

Or you could use a fixed-length string but always pad it with blanks (or 
whatever) up to the fixed length -- see Ada.Strings.Fixed for several 
useful operations on such strings. Depends on what you want...

^ permalink raw reply	[relevance 5%]

* Re: Empty String confusion; Positive and Natural
  @ 2021-11-30  8:29  5%     ` Simon Wright
  2021-11-30  8:34  5%     ` Niklas Holsti
  1 sibling, 0 replies; 200+ results
From: Simon Wright @ 2021-11-30  8:29 UTC (permalink / raw)


Kevin Chadwick <kevc3no4@gmail.com> writes:

>> It would clarify your question if you would show the declaration of
>> that record type. Does it use the String type, or the
>> Unbounded_String type?
>
> Hopefully I will have a doh moment when I get into the office in the
> morning and post code. I am getting a range check exception when I
> assign "" to a standard.String in a record by returning the record
> from a function. Surely, I must have caused it somehow.

If you declare S : String (1 .. 5) and you want to assign a string "foo"
to the whole of S you are forbidden to do so by the language: you have
to assign 5 characters, no more, no fewer.

This can be a royal pain, so we have Ada.Strings.Bounded (if you know
the maximum length) or .Unbounded (if you don't, and can afford more
overhead), both of which support variable-length strings.

^ permalink raw reply	[relevance 5%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  2021-02-27  9:14  0%   ` Blady
@ 2021-03-06 18:13  0%     ` Blady
  0 siblings, 0 replies; 200+ results
From: Blady @ 2021-03-06 18:13 UTC (permalink / raw)


Le 27/02/2021 à 10:14, Blady a écrit :
> Le 11/02/2021 à 09:19, Emmanuel Briot a écrit :
>> There is clearly a need here, given the number of implementations out 
>> there. I had also implemented GNATCOLL.Strings 4 years ago, with 
>> similar goals to yours:
>>    - unicode support (via generic formal parameters and traits 
>> packages, so you can use UTF8, UTF16,... internally)
>>    - unbounded strings (with optional copy-on-write)
>>    - task safety (using traits to chose what kind of counter to use)
>>    - performance (small-string optimization: no memory alloc for 
>> strings of 18 characters or less)
>>    - extended API (all missing subprograms from Ada.Strings.Unbounded)
>>    - extensive testing
>>
>> I must admit I am not sure why AdaCore chose to write VSS instead of 
>> improving one of their string implementations (ada.strings.unbounded, 
>> gnatcoll.strings,...)
>> My initial idea had been that it would be possible to provide a nice 
>> generic package, highly configurable via traits, on top of which we 
>> could reimplement ada.strings.unbounded,
>> ada.strings.bounded,...) but I left AdaCore before that could be 
>> accomplished.
> 
> I'm preparing some optimization when the character set is reduced thus 
> the internal structure will adapt to the actual content.
> But the memory management is bad, the set of API is very basic.
> I'll be glad that you can help.
> 
>> I took a look at VSS and find the API confusing. Your API UXString is 
>> at least much clearer (if lacking doc at the moment :-)
> 
> Some documentation has been added in a form of comments of each API:
> https://github.com/Blady-Com/UXStrings/commit/2bee0ab61841f5e319533b67d2747dda66aa9bd7#diff-90cde6014508061fab9d62e58b327815a954859e5da8a1fd655fa4e5854e7ac5 
> 
>> I am hoping that the work on Alire (Ada package manager) will 
>> ultimately help us find one implementation that is good enough for 
>> everyone,
>> and could ultimately become part of the language.

UXStrings is now available with Alire 
(https://alire.ada.dev/crates/uxstrings), in your Alire project, just 
add UXStrings dependency:

% alr with uxstrings

Thus you can import the UXStrings package in your programs.

Pascal.

PS: for French readers, while referencing UXStrings on Alire, I make the 
opportunity to write a short howto with ALire:
https://blady.pagesperso-orange.fr/a_savoir.html#alire


^ permalink raw reply	[relevance 0%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  2021-02-11  8:19  6% ` Emmanuel Briot
@ 2021-02-27  9:14  0%   ` Blady
  2021-03-06 18:13  0%     ` Blady
  0 siblings, 1 reply; 200+ results
From: Blady @ 2021-02-27  9:14 UTC (permalink / raw)


Le 11/02/2021 à 09:19, Emmanuel Briot a écrit :
> There is clearly a need here, given the number of implementations out there. I had also implemented GNATCOLL.Strings 4 years ago, with similar goals to yours:
>    - unicode support (via generic formal parameters and traits packages, so you can use UTF8, UTF16,... internally)
>    - unbounded strings (with optional copy-on-write)
>    - task safety (using traits to chose what kind of counter to use)
>    - performance (small-string optimization: no memory alloc for strings of 18 characters or less)
>    - extended API (all missing subprograms from Ada.Strings.Unbounded)
>    - extensive testing
> 
> I must admit I am not sure why AdaCore chose to write VSS instead of improving one of their string implementations (ada.strings.unbounded, gnatcoll.strings,...)
> My initial idea had been that it would be possible to provide a nice generic package, highly configurable via traits, on top of which we could reimplement ada.strings.unbounded,
> ada.strings.bounded,...) but I left AdaCore before that could be accomplished.

I'm preparing some optimization when the character set is reduced thus 
the internal structure will adapt to the actual content.
But the memory management is bad, the set of API is very basic.
I'll be glad that you can help.

> I took a look at VSS and find the API confusing. Your API UXString is at least much clearer (if lacking doc at the moment :-)

Some documentation has been added in a form of comments of each API:
https://github.com/Blady-Com/UXStrings/commit/2bee0ab61841f5e319533b67d2747dda66aa9bd7#diff-90cde6014508061fab9d62e58b327815a954859e5da8a1fd655fa4e5854e7ac5

> I am hoping that the work on Alire (Ada package manager) will ultimately help us find one implementation that is good enough for everyone,
> and could ultimately become part of the language.

Alire registration is on the way:
https://github.com/alire-project/alire-index/pull/250

Pascal.

^ permalink raw reply	[relevance 0%]

* Re: [ANN] UXStrings package available (UXS_20210207).
  @ 2021-02-11  8:19  6% ` Emmanuel Briot
  2021-02-27  9:14  0%   ` Blady
  0 siblings, 1 reply; 200+ results
From: Emmanuel Briot @ 2021-02-11  8:19 UTC (permalink / raw)


There is clearly a need here, given the number of implementations out there. I had also implemented GNATCOLL.Strings 4 years ago, with similar goals to yours:
  - unicode support (via generic formal parameters and traits packages, so you can use UTF8, UTF16,... internally)
  - unbounded strings (with optional copy-on-write)
  - task safety (using traits to chose what kind of counter to use)
  - performance (small-string optimization: no memory alloc for strings of 18 characters or less)
  - extended API (all missing subprograms from Ada.Strings.Unbounded)
  - extensive testing

I must admit I am not sure why AdaCore chose to write VSS instead of improving one of their string implementations (ada.strings.unbounded, gnatcoll.strings,...)
My initial idea had been that it would be possible to provide a nice generic package, highly configurable via traits, on top of which we could reimplement ada.strings.unbounded,
ada.strings.bounded,...) but I left AdaCore before that could be accomplished.

I took a look at VSS and find the API confusing. Your API UXString is at least much clearer (if lacking doc at the moment :-)

I am hoping that the work on Alire (Ada package manager) will ultimately help us find one implementation that is good enough for everyone,
and could ultimately become part of the language.

Emmanuel

^ permalink raw reply	[relevance 6%]

* Re: How to get Ada to “cross the chasm”?
  2018-04-30 11:28  4% ` Mehdi Saada
@ 2018-04-30 12:39  0%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-04-30 12:39 UTC (permalink / raw)


On 2018-04-30 13:28, Mehdi Saada wrote:
> For dictionnaries, you can instantiate ada.strings.bounded ou unbounded, to get a variable-length string, then instantiate Ada.containers.bounded_hashed_maps like this:

Or, I suppose, Containers.Indefinite_Ordered_Maps.

However, from a string map I would expect bit more functionality than 
either map or "dictionary" offers. It also depends on whether the target 
objects in the map must be mutable, have an identity etc.

> Sure, there are no containers aggregates which would make the syntax more natural as in Python,

I don't find Python syntax of aggregates natural. It is rather 
incredibly cumbersome, counter-intuitive, lacks regularity and clarity 
Ada syntax has.

> but it's being studied for the next Ada. It doesn't hinder the use so much, though.

Well, I cautiously doubt it. As the history with iterators and implicit 
derefence shows we unlikely get the syntax and functionality we wanted.

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


^ permalink raw reply	[relevance 0%]

* Re: How to get Ada to “cross the chasm”?
  @ 2018-04-30 11:28  4% ` Mehdi Saada
  2018-04-30 12:39  0%   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Mehdi Saada @ 2018-04-30 11:28 UTC (permalink / raw)


For dictionnaries, you can instantiate ada.strings.bounded ou unbounded, to get a variable-length string, then instantiate Ada.containers.bounded_hashed_maps like this:

first you have to overload the hash function a bit since it takes only the type String.
function Hash(A: your_string_type) is
(ada.string.Hash(To_String(A)));

then you create your hashed map package:
package hashed_maps is new ada.containers.bounded_hashed_maps
(Key_Type => your_string_type, Element_Type => another_string_type, Hash => Ada.string.Hash, Equivalent_Keys => "=");

and there you have your dictionary.
DIct: Map (Nombre_de_mots_max, Default_modulus(Nombre_de_mots_max));

I let you understand the subprograms, but most of them are self-evident, and repeat themselves all over the containers libraries.

Sure, there are no containers aggregates which would make the syntax more natural as in Python, but it's being studied for the next Ada. It doesn't hinder the use so much, though.


^ permalink raw reply	[relevance 4%]

* Re: ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782
  @ 2018-01-15  3:23  5% ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2018-01-15  3:23 UTC (permalink / raw)


On 18-01-15 03:18 , Mehdi Saada wrote:
> This if statement exactly, seems to raise
> "ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782"(No indication of line, so I can't know more).
> What does this exception means ?

That you have tried to access a non-existent element of some kind of 
string (Bounded or Unbounded). Note that Ada.Strings.Bounded and 
Ada.Strings.Unbounded are both children of Ada.Strings, where this 
exception is declared, and both use this exception.

> You can see there's no string type variable to be accessed, here.
> CHAINE is of UNBOUNDED_STRING type.
> LA_PILE is a stack of characters,
> EMPILER means "putting on the stack's top" in french.
>
> if IS_BASIC(ELEMENT(CHAINE,IND)) then

The exception probably comes from the above call of ELEMENT.

>    EMPILER(LA_PILE,ELEMENT(CHAINE,IND));
> else DELETE(CHAINE, IND,IND);
> end if;
>
> It's enclosed in:
> for Ind in 1..Length(CHAINE) loop

Note that the iteration range, 1 .. Length(CHAINE), is computed here 
using the value of CHAINE at the *start* of the loop, and is not 
recomputed during the execution of the loop.

>         begin
>             if IS_BASIC(ELEMENT(CHAINE,IND)) then
>                     EMPILER(LA_PILE,ELEMENT(CHAINE,IND));
>             else DELETE(CHAINE, IND,IND);

This DELETE shortens CHAINE. If it occurs one or more times during the 
iteration of the loop, before the last iteration of the loop, then at 
some later iteration the index Ind will be larger than the (new) 
Length(CHAINE), and the exception results.

>             end if;
>          end;
> end loop;

To fix this error, you must make the loop recompute Length(CHAINE) when 
needed, for example in this way:

    for Ind in 1 .. Length(CHAINE) loop

       exit when Ind > Length(CHAINE);

       if IS_BASIC ...
          ...
       end if;

    end loop;

However, I would write it like this, to avoid the confusion of a double 
check of Length(CHAINE):

    Ind : Positive := 1;
    ...

    while Ind <= Length(CHAINE) loop

       if IS_BASIC ...
          ...
       end if;

       Ind := Ind + 1;

    end loop;

Note that in the "while" loop, the condition (Ind <= Length(CHAINE)) is 
evaluated on every loop iteration. In a "for" loop, the index range is 
evaluated once, at the start of the loop.

However, I suspect that there is a deeper error in your loop, related to 
the DELETE. Consider what happens if CHAINE is, say, "ABCDEFG", and the 
DELETE occurs for the first time when Ind = 3, at CHAINE(Ind) = 'C'. 
When you DELETE(CHAINE, 3, 3), CHAINE becomes "ABDEFG". On the next loop 
iteration, Ind = 4, which means the loop checks CHAINE(4) = 'E'. The 
letter 'D', which used to be CHAINE(4) but is now CHAINE(3), is not checked.

Do you really need to DELETE in the loop? If you do, then you must take 
into account that DELETE renumbers the elements of CHAINE after the 
deleted character.

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


^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Unbounded vs Ada.Containers.Indefinite_Holders
  @ 2017-09-23  9:16  5%           ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2017-09-23  9:16 UTC (permalink / raw)


On 09/23/2017 10:09 AM, Dmitry A. Kazakov wrote:
> On 2017-09-23 00:15, Victor Porton wrote:
>>
>> In my opinion, it would be better to change RM phrasing from "null string"
>> to "empty string", because in some other languages (notably C) NULL means
>> something other. It is just confusing.
> 
> The adjective null and the noun null are distinct parts of speech. C's noun null 
> is an abbreviation of null pointer. If pointers can be null so strings can.

Another way to look at it: Ada has the formal concepts of:

* null access value ARM 4.2(9)
* null array 3.6.1(7)
* null constraint 3.2(7/2)
* null_exclusion 3.10(5.1/2)
* null extension 3.9.1(4.1/2)
* null procedure 6.7(3/3)
* null range 3.5(4)
* null record 3.8(15)
* null slice 4.1.2(7)
* null string literal 2.6(6)
* null value (of an access type) 3.10(13/2)
* null_statement 5.1(6)

not to mention the language-defined identifiers

Null_Address
    in System   13.7(12)
Null_Bounded_String
    in Ada.Strings.Bounded   A.4.4(7)
Null_Id
    in Ada.Exceptions   11.4.1(2/2)
Null_Occurrence
    in Ada.Exceptions   11.4.1(3/2)
Null_Ptr
    in Interfaces.C.Strings   B.3.1(7)
Null_Set
    in Ada.Strings.Maps   A.4.2(5)
    in Ada.Strings.Wide_Maps   A.4.7(5)
    in Ada.Strings.Wide_Wide_Maps   A.4.8(5/2)
Null_Task_Id
    in Ada.Task_Identification   C.7.1(2/2)
Null_Unbounded_String
    in Ada.Strings.Unbounded   A.4.5(5)

(Just look under N in the index.)

It's called overloading. Many of these cases refer to things that can have 
components and mean one with zero components: a null record has no components, a 
null array has no components ('Length = 0), a null string literal has no 
characters, a null set has no members, ... It should not be confusing.

-- 
Jeff Carter
"You cheesy lot of second-hand electric donkey-bottom biters."
Monty Python & the Holy Grail
14

^ permalink raw reply	[relevance 5%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 17:29  0%                                               ` Egil H H
@ 2017-09-12 19:14  0%                                                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 19:14 UTC (permalink / raw)


On 2017-09-12 19:29, Egil H H wrote:
> On Tuesday, September 12, 2017 at 7:17:38 PM UTC+2, Dmitry A. Kazakov wrote:
>> No, it does not work. Try
>>
>>      package S_1000 is new Ada.Strings.Bounded (1000);
>>      package S_10 is new Ada.Strings.Bounded (10);
>>
>>      X : S_1000.Bounded_String;
>>      Y : S_10.Bounded_String;
>>
>>      X := Y;
>>
>> A proper implementation of bounded-length string, provided we needed
>> them, should have worked like this:
>>
>>      X : Bounded_String (1000); -- 1000 is my limit, now I am ""
>>      Y : Bounded_String (10) := "abc"; -- 10 is mine, now I am "abc"
>>
>>      X := Y; -- We are both strings, don't we?
> 
> Ah, so yo want to give up type safety... those are different types,
> instantiated for different purposes.
Sure, like

    X : String (1..1000);
    Y : String (1..10);

Length constraint has nothing to do with type safety. E.g.

    type Address is new Bounded_String (30);
    type Name is new Bounded_String (30);

Same constraint different types and conversely.

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

^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 17:17  7%                                             ` Dmitry A. Kazakov
@ 2017-09-12 17:29  0%                                               ` Egil H H
  2017-09-12 19:14  0%                                                 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2017-09-12 17:29 UTC (permalink / raw)


On Tuesday, September 12, 2017 at 7:17:38 PM UTC+2, Dmitry A. Kazakov wrote:
> No, it does not work. Try
> 
>     package S_1000 is new Ada.Strings.Bounded (1000);
>     package S_10 is new Ada.Strings.Bounded (10);
> 
>     X : S_1000.Bounded_String;
>     Y : S_10.Bounded_String;
> 
>     X := Y;
> 
> A proper implementation of bounded-length string, provided we needed 
> them, should have worked like this:
> 
>     X : Bounded_String (1000); -- 1000 is my limit, now I am ""
>     Y : Bounded_String (10) := "abc"; -- 10 is mine, now I am "abc"
> 
>     X := Y; -- We are both strings, don't we?

Ah, so yo want to give up type safety... those are different types, instantiated for different purposes.
You're on your own, then... 
Good luck with your unsafe memory hog.


^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 17:03  5%                                           ` Egil H H
@ 2017-09-12 17:17  7%                                             ` Dmitry A. Kazakov
  2017-09-12 17:29  0%                                               ` Egil H H
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 17:17 UTC (permalink / raw)


On 2017-09-12 19:03, Egil H H wrote:
> On Tuesday, September 12, 2017 at 6:59:09 PM UTC+2, Dmitry A. Kazakov wrote:
>> Right, but discriminant is a natural way to express constraint in Ada.
>> Formal generic parameter is a very bad way doing that.
>>
>> As for having default value it is a requirement to have the type
>> constrained, which is a requirement to make assignment work. Which has
>> undesired implications on the type representation. Sigh.
>>
> 
> Last time I checked, assignment worked perfectly with Ada.Strings.Bounded.
> Sigh, right back to you.

No, it does not work. Try

    package S_1000 is new Ada.Strings.Bounded (1000);
    package S_10 is new Ada.Strings.Bounded (10);

    X : S_1000.Bounded_String;
    Y : S_10.Bounded_String;

    X := Y;

A proper implementation of bounded-length string, provided we needed 
them, should have worked like this:

    X : Bounded_String (1000); -- 1000 is my limit, now I am ""
    Y : Bounded_String (10) := "abc"; -- 10 is mine, now I am "abc"

    X := Y; -- We are both strings, don't we?

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

^ permalink raw reply	[relevance 7%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12 17:03  5%                                           ` Egil H H
  2017-09-12 17:17  7%                                             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2017-09-12 17:03 UTC (permalink / raw)


On Tuesday, September 12, 2017 at 6:59:09 PM UTC+2, Dmitry A. Kazakov wrote:
> Right, but discriminant is a natural way to express constraint in Ada. 
> Formal generic parameter is a very bad way doing that.
> 
> As for having default value it is a requirement to have the type 
> constrained, which is a requirement to make assignment work. Which has 
> undesired implications on the type representation. Sigh.
>

Last time I checked, assignment worked perfectly with Ada.Strings.Bounded.
Sigh, right back to you.


^ permalink raw reply	[relevance 5%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12 16:58  6%                   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 16:58 UTC (permalink / raw)


On 2017-09-12 18:30, Shark8 wrote:
> On Tuesday, September 12, 2017 at 4:07:27 AM UTC-6, Dmitry A. Kazakov wrote:
>>
>> No DB bindings I know deploy bounded-length strings.
> 
> Isn't that a failing of those bindings? (Just like we could have a
> thin C-binding which used return codes.)
If you mean the side turned towards the DB, it is a requirement, since 
the counterpart is a char * or void *.

If you mean the Ada interface's side, it is convenience. Bounded_Strings 
are difficult to use, while the advantage is zero. If the DB has a field 
constraint that is dynamic on the Ada side. There is no way you could 
push that constraint into the instance of Ada.Strings.Bounded.

Since copying is involved anyway, there is no reason not to have

    Fetch (Column)

just returning String of the actual length. Simple and clean.

If we wanted in-place semantics, a stream is the answer. Fetch would 
supply chunks of data which are accumulated in the stream. There are 
lots of protocols working this way, e.g. HTTP's chunked transfer.

The stream can be backed by a String on an embedded system or by a 
container of dynamically allocated memory chunks. Anyway, no good reason 
to use Ada.Strings.Bounded.

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

^ permalink raw reply	[relevance 6%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 16:15  4%                                   ` Egil H H
@ 2017-09-12 16:40  0%                                     ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 16:40 UTC (permalink / raw)


On 2017-09-12 18:15, Egil H H wrote:
> On Tuesday, September 12, 2017 at 5:55:34 PM UTC+2, Dmitry A. Kazakov wrote:
>>
>> How is that different from:
>>
>>      package Foo is new Ada.Strings.Bounded (1000);
>>
>> ?
> 
> The difference?
> You have one string type that will always allocate 1000 Characters
> for  every variable of the type, regardless of how many the user specifies as
> max. Ada.Strings.Bounded will allocate as many as the user specifies
> as max, which is 10 in the part of your example i quoted. So you
> would use  9990% more memory...

Do you imply that Bounded_String deploys heap? I would consider such 
implementation a bug. Otherwise you will need two instances and two 
different types, which is not the intended use.

The example only illustrates how discriminants work with assignment and 
components.

> And again, how did you choose 1000? How do you know that will be
> enough for all users of your string type?

This is why Bounded_String are not used. The problem space almost never 
provides any upper bound. So the bound is an implementation constraint 
and thus a premature optimization of worst kind.

> Or do you copy/paste the
> string type every time you need a new max length?

Sure, this what generic packages basically are, dressed up macros.

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

^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 15:55  5%                                 ` Dmitry A. Kazakov
@ 2017-09-12 16:15  4%                                   ` Egil H H
  2017-09-12 16:40  0%                                     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2017-09-12 16:15 UTC (permalink / raw)


On Tuesday, September 12, 2017 at 5:55:34 PM UTC+2, Dmitry A. Kazakov wrote:
> 
> How is that different from:
> 
>     package Foo is new Ada.Strings.Bounded (1000);
> 
> ?

The difference?
You have one string type that will always allocate 1000 Characters for every variable of the type, regardless of how many the user specifies as max. 
Ada.Strings.Bounded will allocate as many as the user specifies as max, which is 10 in the part of your example i quoted. So you would use 9990% more memory...

And again, how did you choose 1000? How do you know that will be enough for all users of your string type? Or do you copy/paste the string type every time you need a new max length? 


^ permalink raw reply	[relevance 4%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12 15:59  6%                                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 15:59 UTC (permalink / raw)


On 2017-09-12 16:07, Egil H H wrote:
> On Tuesday, September 12, 2017 at 3:43:40 PM UTC+2, Dmitry A. Kazakov wrote:
>> So it can do with the custom type:
>>
>> with Ada.Text_IO;  use Ada.Text_IO;
>> procedure Test is
>>      Max : constant := 1000;
>>      subtype Max_Length is Natural range 0..Max;
>>      type Bounded (Size : Max_Length := Max_Length'Last) is record
>>         Length : Max_Length := 0;
>>         Text   : String (1..Size);
>>      end record;
>>      function Value (S : Bounded) return String is
>>      begin
>>         return S.Text (1..S.Length);
>>      end Value;
>>      procedure Set (S : in out Bounded; Value : String) is
>>      begin
>>         S.Length := Value'Length;
>>         S.Text (1..Value'Length) := Value;
>>      end Set;
>>      X : Bounded;
>>      Y : Bounded (10);
>> begin
>>      Set (X, "0123456789ABCDEFGH");
>>      Put_Line ("X=" & Value (X));
>>      Set (Y, "abc");
>>      X := Y;
>>      Put_Line ("X=" & Value (X));
>> end Test;
>>
> 
> ...and you _really_ don't see the value of having all this (and lots
> more) in _one_ place, implemented _once_, tried and tested?

No, I don't see value in bounded-length strings in the first place. So I 
have neither this nor Ada.Strings.Bounded anywhere.

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


^ permalink raw reply	[relevance 6%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12 15:55  5%                                 ` Dmitry A. Kazakov
  2017-09-12 16:15  4%                                   ` Egil H H
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 15:55 UTC (permalink / raw)


On 2017-09-12 16:36, Egil H H wrote:
> On Tuesday, September 12, 2017 at 3:43:40 PM UTC+2, Dmitry A. Kazakov wrote:
>> So it can do with the custom type:
>>
>> with Ada.Text_IO;  use Ada.Text_IO;
>> procedure Test is
>>      Max : constant := 1000;
>>      subtype Max_Length is Natural range 0..Max;
>>      type Bounded (Size : Max_Length := Max_Length'Last) is record
>>         Length : Max_Length := 0;
>>         Text   : String (1..Size);
>>      end record;
>>
> ...
>>      Y : Bounded (10);
> 
> Also, allocating 1000 Characters for a string of max length 10 is hardly an optimal solution...

How is that different from:

    package Foo is new Ada.Strings.Bounded (1000);

?

If you are looking for optimal solutions look elsewhere...

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


^ permalink raw reply	[relevance 5%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 12:56  0%                       ` Egil H H
@ 2017-09-12 13:14  0%                         ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 13:14 UTC (permalink / raw)


On 12/09/2017 14:56, Egil H H wrote:
> On Tuesday, September 12, 2017 at 2:09:53 PM UTC+2, Dmitry A. Kazakov wrote:
>>
>> The same way I supposed to choose it for Ada.Strings.Bounded?
> 
> What? That it shouldn't be a generic? That would bring us back to
> allocating huge amounts of memory per string...

How? What is the difference between giving the bound in a generic 
instantiation vs in a type declaration?

>> As I said there is almost no use for bounded-length strings.
> 
> You may not have need for it. That doesn't necessarily make it true
> for the rest of the world.
I didn't say that. I said that there is no use case for it. Which is not 
same. Regarding the rest of the world, it is even simpler. It is a mere 
empirical fact relatively easy to measure. Take available Ada code base 
and compare how frequently various types of strings are used there.

That nobody actually uses bounded strings does not necessary mean that 
there is no use of bounded strings. Maybe people are uneducated, have 
prejudices etc. But no the thing is indeed useless, therefore not used. 
Could be quietly removed from the standard, nobody would notice...

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


^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12 12:09  6%                     ` Dmitry A. Kazakov
@ 2017-09-12 12:56  0%                       ` Egil H H
  2017-09-12 13:14  0%                         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Egil H H @ 2017-09-12 12:56 UTC (permalink / raw)


On Tuesday, September 12, 2017 at 2:09:53 PM UTC+2, Dmitry A. Kazakov wrote:
> 
> The same way I supposed to choose it for Ada.Strings.Bounded?

What? That it shouldn't be a generic? That would bring us back to allocating huge amounts of memory per string...


> As I said there is almost no use for bounded-length strings. 

You may not have need for it. That doesn't necessarily make it true for the rest of the world.

-- 
~egilhh


^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12 12:09  6%                     ` Dmitry A. Kazakov
  2017-09-12 12:56  0%                       ` Egil H H
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12 12:09 UTC (permalink / raw)


On 12/09/2017 12:48, Egil H H wrote:
> On Tuesday, September 12, 2017 at 12:22:12 PM UTC+2, Dmitry A. Kazakov wrote:
>>
>> Yes, but they would be different. A more close example would be:
>>
>> type Bounded_String (Bound : Natural := Max) is record
>>      Length : Natural := 0;
>>      Text   : String (1..Bound);
>> end record;
> 
> Well, I don't have unlimited memory, so allocating Natural'Last 
> number of Characters for all my strings is not an option for me, but
> I guess YMMV.
> 
> (Sure, you can use a subtype other than Natural, but how do you
> choose an upper bound that is both reasonably large to fit most
> needs, yet  reasonably small to limit memory usage?)

The same way I supposed to choose it for Ada.Strings.Bounded?

As I said there is almost no use for bounded-length strings. It is much 
easier to create new local fixed-length strings all the time. String 
re-assignment must ring alarm bells no sane algorithm should require this.

The only one case where Unbounded_String has a use is when returning 
multiple strings out of a procedure. If ad-hoc tuples were supported 
that won't be necessary either. Though it possible to create a result 
record like:

    type Result (L1, L2, L3 : Natural) is record
       S1 : String (1..L1);
       S2 : String (1..L2);
       S3 : String (1..L3);
    end record;

and I frequently do this, it does not look elegant.

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


^ permalink raw reply	[relevance 6%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12  8:35  6%             ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12  8:35 UTC (permalink / raw)


On 12/09/2017 09:42, Egil H H wrote:
> On Tuesday, September 12, 2017 at 9:02:15 AM UTC+2, Tarjei Jensen wrote:
>> It is different because you don't need to overload := to make it work.
> 
> Substituting a discriminant with a record member does not magically change the behaviour of ":="

It does, because there are rules limiting assignment of discriminated 
records.

Both presented variants are wrong.

The variant with the discriminant is if we assume that the upper bound 
is not a part of the type, but a subtype constraint. Specifically it 
would imply an ability to assign strings having different upper bounds.

One of issues limiting use of Ada.Strings.Bounded is that the package is 
generic with the bound given the formal parameter.

P.S. Assignment cannot be reasonably implemented without compiler magic 
because multiple dispatch is not supported.

P.P.S. Not that bounded-length strings were much more usable if the 
bound were a proper constraint and assignment worked across all string 
types...

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

^ permalink raw reply	[relevance 6%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12  7:02  0%         ` Tarjei Jensen
@ 2017-09-12  7:15  0%           ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-09-12  7:15 UTC (permalink / raw)


On 12/09/2017 09:02, Tarjei Jensen wrote:
> On Tuesday, 12 September 2017 08:38:16 UTC+2, gautier...@hotmail.com  wrote:
>> Have a look at the package Ada.Strings.Bounded ...
>> It is rarely encountered in programs, but available since Ada 95.
>> _________________________
>> Gautier's Ada programming
>> http://gautiersblog.blogspot.com/search/label/Ada
>> NB: follow the above link for a valid e-mail address
> 
> Perhaps there is a reason for the non-use?

Yes, bounded-length strings have no practical use in Ada.

The reason for that is that differently to other languages Ada can 
return fixed-length strings on the stack and can pass string slices down 
where a fixed-length string is expected. This eliminates most of the 
cases for bounded-length strings, the minuscule rest is handled by 
Unbounded_Strings.

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

^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  2017-09-12  6:38  5%       ` gautier_niouzes
@ 2017-09-12  7:02  0%         ` Tarjei Jensen
  2017-09-12  7:15  0%           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Tarjei Jensen @ 2017-09-12  7:02 UTC (permalink / raw)


On Tuesday, 12 September 2017 08:38:16 UTC+2, gautier...@hotmail.com  wrote:
> Have a look at the package Ada.Strings.Bounded ...
> It is rarely encountered in programs, but available since Ada 95.
> _________________________ 
> Gautier's Ada programming 
> http://gautiersblog.blogspot.com/search/label/Ada 
> NB: follow the above link for a valid e-mail address

Perhaps there is a reason for the non-use?


^ permalink raw reply	[relevance 0%]

* Re: Community Input for the Maintenance and Revision of the Ada Programming Language
  @ 2017-09-12  6:38  5%       ` gautier_niouzes
  2017-09-12  7:02  0%         ` Tarjei Jensen
    1 sibling, 1 reply; 200+ results
From: gautier_niouzes @ 2017-09-12  6:38 UTC (permalink / raw)


Have a look at the package Ada.Strings.Bounded ...
It is rarely encountered in programs, but available since Ada 95.
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 


^ permalink raw reply	[relevance 5%]

* Re: Bounded String question
  2015-11-12 18:03  0%                 ` G.B.
  2015-11-12 18:13  0%                   ` Serge Robyns
@ 2015-11-12 19:37  0%                   ` Randy Brukardt
  1 sibling, 0 replies; 200+ results
From: Randy Brukardt @ 2015-11-12 19:37 UTC (permalink / raw)


"G.B." <bauhaus@futureapps.invalid> wrote in message 
news:n22k4s$vk3$1@dont-email.me...
> On 11.11.15 21:40, AdaMagica wrote:
>> Am Mittwoch, 11. November 2015 21:32:39 UTC+1 schrieb Serge Robyns:
>>> This how this whole thread started.  That construct does not work
>>> with pragma preelaborate.  But this was exactly the code I had initially 
>>> :-)
>>
>> No complaint from GNAT GPL 2015:
>> --------------------------------
>>
>> with Ada.Strings; use Ada.Strings;
>> with Ada.Strings.Bounded;
>>
>> procedure BS_Test is
>>
>>    pragma Preelaborate;
>
> Are the requirements for Elaborate (or for Pure) different for
> a library unit that is a subprogram?

Yes. The Preelaborate rules only apply at library level, and a procedure is 
not library level by definition.

One cannot declare a preelaborable bounded string constant, as the 
initialization will necessarily fail the preelaboration checks.

I recently worked out a proposal that could have changed that, but it became 
way too complex and it went nowhere. (Recall the similar discussion here 
about having a preelaborable constant of type Address.)

                                         Randy.


                     Randy.


^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-12 18:13  0%                   ` Serge Robyns
@ 2015-11-12 18:14  0%                     ` Serge Robyns
  0 siblings, 0 replies; 200+ results
From: Serge Robyns @ 2015-11-12 18:14 UTC (permalink / raw)


On Thursday, 12 November 2015 19:13:17 UTC+1, Serge Robyns  wrote:
> On Thursday, 12 November 2015 19:03:19 UTC+1, G.B.  wrote:
> > On 11.11.15 21:40, AdaMagica wrote:
> > > Am Mittwoch, 11. November 2015 21:32:39 UTC+1 schrieb Serge Robyns:
> > >> This how this whole thread started.  That construct does not work
> > >> with pragma preelaborate.  But this was exactly the code I had initially :-)
> > >
> > > No complaint from GNAT GPL 2015:
> > > --------------------------------
> > >
> > > with Ada.Strings; use Ada.Strings;
> > > with Ada.Strings.Bounded;
> > >
> > > procedure BS_Test is
> > >
> > >    pragma Preelaborate;
> > 
> > Are the requirements for Elaborate (or for Pure) different for
> > a library unit that is a subprogram? GNAT does not rejected this
> > "pure" one either:
> > 
> > procedure Purity (A : Integer) is
> > 
> >     pragma Pure (Purity);
> > 
> >     type P is access String;
> > 
> >     X : P := new String'("abc");
> >     Y : String := Integer'Image (A);
> >     Z : String := Y (1) & Y (A);
> > 
> > begin
> >     Y (3) := X (1);
> > end Purity;
> > 
> > Diagnostics change in the opposite direction when the same declarations
> > appear in a package spec.
> 
> I do confirm the exact diagnostic.

The exact same diagnostic to complete my initial statement.

^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-12 18:03  0%                 ` G.B.
@ 2015-11-12 18:13  0%                   ` Serge Robyns
  2015-11-12 18:14  0%                     ` Serge Robyns
  2015-11-12 19:37  0%                   ` Randy Brukardt
  1 sibling, 1 reply; 200+ results
From: Serge Robyns @ 2015-11-12 18:13 UTC (permalink / raw)


On Thursday, 12 November 2015 19:03:19 UTC+1, G.B.  wrote:
> On 11.11.15 21:40, AdaMagica wrote:
> > Am Mittwoch, 11. November 2015 21:32:39 UTC+1 schrieb Serge Robyns:
> >> This how this whole thread started.  That construct does not work
> >> with pragma preelaborate.  But this was exactly the code I had initially :-)
> >
> > No complaint from GNAT GPL 2015:
> > --------------------------------
> >
> > with Ada.Strings; use Ada.Strings;
> > with Ada.Strings.Bounded;
> >
> > procedure BS_Test is
> >
> >    pragma Preelaborate;
> 
> Are the requirements for Elaborate (or for Pure) different for
> a library unit that is a subprogram? GNAT does not rejected this
> "pure" one either:
> 
> procedure Purity (A : Integer) is
> 
>     pragma Pure (Purity);
> 
>     type P is access String;
> 
>     X : P := new String'("abc");
>     Y : String := Integer'Image (A);
>     Z : String := Y (1) & Y (A);
> 
> begin
>     Y (3) := X (1);
> end Purity;
> 
> Diagnostics change in the opposite direction when the same declarations
> appear in a package spec.

I do confirm the exact diagnostic.


^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-11 20:40  6%               ` AdaMagica
@ 2015-11-12 18:03  0%                 ` G.B.
  2015-11-12 18:13  0%                   ` Serge Robyns
  2015-11-12 19:37  0%                   ` Randy Brukardt
  0 siblings, 2 replies; 200+ results
From: G.B. @ 2015-11-12 18:03 UTC (permalink / raw)


On 11.11.15 21:40, AdaMagica wrote:
> Am Mittwoch, 11. November 2015 21:32:39 UTC+1 schrieb Serge Robyns:
>> This how this whole thread started.  That construct does not work
>> with pragma preelaborate.  But this was exactly the code I had initially :-)
>
> No complaint from GNAT GPL 2015:
> --------------------------------
>
> with Ada.Strings; use Ada.Strings;
> with Ada.Strings.Bounded;
>
> procedure BS_Test is
>
>    pragma Preelaborate;

Are the requirements for Elaborate (or for Pure) different for
a library unit that is a subprogram? GNAT does not rejected this
"pure" one either:

procedure Purity (A : Integer) is

    pragma Pure (Purity);

    type P is access String;

    X : P := new String'("abc");
    Y : String := Integer'Image (A);
    Z : String := Y (1) & Y (A);

begin
    Y (3) := X (1);
end Purity;

Diagnostics change in the opposite direction when the same declarations
appear in a package spec.

^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-11 20:06  7%         ` Serge Robyns
  2015-11-11 20:23  7%           ` AdaMagica
@ 2015-11-11 20:42  0%           ` Jeffrey R. Carter
  1 sibling, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2015-11-11 20:42 UTC (permalink / raw)


On 11/11/2015 01:06 PM, Serge Robyns wrote:
> 
> I had to specify the full signature of To_Bounded_String, including default value to make it work with sub types.

Sorry, I forgot the Drop parameter.

>    package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);
> 
>    type OS is new BS.Bounded_String;
>    
>    No_OS : OS renames BS.Null_Bounded_String;   
>    function To_OS (Source : in String;
>                   Drop : in Truncation := Error) return OS renames BS.To_Bounded_String;

These won't work. BS.Null_Bounded_String has type BS.Bounded_String, not OS.
However, you can convert BS.Null_Bounded_String

No_OS : constant OS := OS (BS.Null_Bounded_String);

or create your own

No_OS : constant OS := To_String ("");

Calling To_String requires elaboration.

Similarly, BS.To_Bounded_String returns BS.Bounded_String, not OS. However,
there is a directly visible To_Bounded_String that returns OS, and you can
rename that if you want:

function To_OS (Source : in String; Drop : in Truncation := Error)
return OS renames To_Bounded_String;

-- 
Jeff Carter
"When Roman engineers built a bridge, they had to stand under it
while the first legion marched across. If programmers today
worked under similar ground rules, they might well find
themselves getting much more interested in Ada!"
Robert Dewar
62


^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-11 20:32  0%             ` Serge Robyns
@ 2015-11-11 20:40  6%               ` AdaMagica
  2015-11-12 18:03  0%                 ` G.B.
  0 siblings, 1 reply; 200+ results
From: AdaMagica @ 2015-11-11 20:40 UTC (permalink / raw)


Am Mittwoch, 11. November 2015 21:32:39 UTC+1 schrieb Serge Robyns:
> This how this whole thread started.  That construct does not work
> with pragma preelaborate.  But this was exactly the code I had initially :-)

No complaint from GNAT GPL 2015:
--------------------------------

with Ada.Strings; use Ada.Strings;
with Ada.Strings.Bounded;

procedure BS_Test is

  pragma Preelaborate;

  package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

  type OS is new BS.Bounded_String;
   
  No_OS: constant OS := OS (BS.Null_Bounded_String);  -- renaming does not work here, only allowed for tagged types

  function To_OS (Source: in String;
                  Drop  : in Truncation := Error) return OS renames BS_Test.To_Bounded_String;  -- inherited operations are implicitly defined in the same declarative region as the derived type

   B: OS     := To_OS ("asdfghjkl");
   S: String := To_String (B);

begin -- BS_Test
   null;
end BS_Test; 

gprbuild -ws -c -f -u -PC:\Users\Grein\Documents\Christoph\Ada\Spielplatz\spielplatz.gpr -XGeneration=Ada_2012 bs_test.adb
gcc -c -gnato -g -fstack-check -gnata -gnatf -gnat12 bs_test.adb
[2015-11-11 21:37:27] process terminated successfully, elapsed time: 02.07s


^ permalink raw reply	[relevance 6%]

* Re: Bounded String question
  2015-11-11 20:23  7%           ` AdaMagica
@ 2015-11-11 20:32  0%             ` Serge Robyns
  2015-11-11 20:40  6%               ` AdaMagica
  0 siblings, 1 reply; 200+ results
From: Serge Robyns @ 2015-11-11 20:32 UTC (permalink / raw)


On Wednesday, 11 November 2015 21:23:58 UTC+1, AdaMagica  wrote:
> This works:
> 
> 
> with Ada.Strings; use Ada.Strings;
> with Ada.Strings.Bounded;
> 
> procedure BS_Test is
>    package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);
> 
>    type OS is new BS.Bounded_String;
>    
>    No_OS : constant OS := OS (BS.Null_Bounded_String);  -- renaming does not work here, only allowed for tagged types

This how this whole thread started.  That construct does not work with pragma preelaborate.  But this was exactly the code I had initially :-)


^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-11 20:06  7%         ` Serge Robyns
@ 2015-11-11 20:23  7%           ` AdaMagica
  2015-11-11 20:32  0%             ` Serge Robyns
  2015-11-11 20:42  0%           ` Jeffrey R. Carter
  1 sibling, 1 reply; 200+ results
From: AdaMagica @ 2015-11-11 20:23 UTC (permalink / raw)


This works:


with Ada.Strings; use Ada.Strings;
with Ada.Strings.Bounded;

procedure BS_Test is
   package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type OS is new BS.Bounded_String;
   
   No_OS : constant OS := OS (BS.Null_Bounded_String);  -- renaming does not work here, only allowed for tagged types

   function To_OS (Source : in String;
                  Drop : in Truncation := Error) return OS renames BS_Test.To_Bounded_String;  -- inherited operations are implicitly defined in the same declarative region as the derived type

   B : OS     := To_OS ("asdfghjkl");
   S : String := To_String (B);
begin -- BS_Test
   null;
end BS_Test; 


^ permalink raw reply	[relevance 7%]

* Re: Bounded String question
  2015-11-11 17:27  6%       ` Jeffrey R. Carter
@ 2015-11-11 20:06  7%         ` Serge Robyns
  2015-11-11 20:23  7%           ` AdaMagica
  2015-11-11 20:42  0%           ` Jeffrey R. Carter
  0 siblings, 2 replies; 200+ results
From: Serge Robyns @ 2015-11-11 20:06 UTC (permalink / raw)


I ended up using a per "type" bounded string instance.  This will anyway give me the most flexibility as each could have a different length in the final version.

package Client_Name_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length (20);
subtype T_Client_Name is Client_Name_Strings.Bounded_String;
...
No_Client_Name : T_Client_Name renames Client_Name_Strings.Null_Bounded_String;
...
function To_Client_Name
  (Source : in String;
   Drop   : in Truncation := Error)
   return T_Client_Name
   renames Client_Name_Strings.To_Bounded_String;

I had to specify the full signature of To_Bounded_String, including default value to make it work with sub types.

With this construct the package also compiles and run with pragma preelaborate.
Moreover, "users" of the package will use types, constants and explicit functions and I can change the implementation at will.

On Wednesday, 11 November 2015 18:27:41 UTC+1, Jeffrey R. Carter  wrote:
> When you create a derived type, such as T_Client_Name, it inherits all the
> primitive operations of its parent. In this case, that includes To_String and
> To_Bounded_String. So you get functions
> 
> function To_String (S : T_Client_Name) return String;
> function To_Bounded_String (S : String) return T_Client_Name;
> 
> Basically, all the operations in Generic_Bounded_Length that have a parameter or
> return type of Bounded_String, with Bounded_String replaced by the name of the
> derived type.
> 
> If you want something named To_T_Client_Name then of course you have to define
> it yourself:
> 
> function To_T_Client_Name (S : String ) return T_Client_Name renames
> To_Bounded_String;
> 

I'm not sure this works, well not how I tried.

with Ada.Strings; use Ada.Strings;
with Ada.Strings.Bounded;

procedure BS_Test is
   package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type OS is new BS.Bounded_String;
   
   No_OS : OS renames BS.Null_Bounded_String;   
   function To_OS (Source : in String;
                  Drop : in Truncation := Error) return OS renames BS.To_Bounded_String;

   B : OS     := To_OS ("asdfghjkl");
   S : String := To_String (B);
begin -- BS_Test
   null;
end BS_Test;

gives

bs_test.adb:9:25: expected private type "OS" defined at line 7
bs_test.adb:9:25: found private type "Ada.Strings.Bounded.Bounded_String" from instance at line 5
bs_test.adb:10:04: no visible subprogram matches the specification for "To_OS"


^ permalink raw reply	[relevance 7%]

* Re: Bounded String question
  @ 2015-11-11 17:27  6%       ` Jeffrey R. Carter
  2015-11-11 20:06  7%         ` Serge Robyns
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2015-11-11 17:27 UTC (permalink / raw)


On 11/11/2015 06:43 AM, Serge Robyns wrote:
> On Wednesday, 11 November 2015 11:52:13 UTC+1, Serge Robyns  wrote:
>> I've had to write loads of functions like "To_Client_Name (Name : in
>> String) >return T_Client_Name is (T_Client_Name
>> (P_Strings.To_Bounded_String (Name));"

Only if you want a name other than To_Bounded_String.

> What does escape my understanding is why can I use To_String with any type
> defined from P_Strings but have to define all the To_xyz explicitly.  Is
> there a kind of "hidden" conversion applied in that case?

When you create a derived type, such as T_Client_Name, it inherits all the
primitive operations of its parent. In this case, that includes To_String and
To_Bounded_String. So you get functions

function To_String (S : T_Client_Name) return String;
function To_Bounded_String (S : String) return T_Client_Name;

Basically, all the operations in Generic_Bounded_Length that have a parameter or
return type of Bounded_String, with Bounded_String replaced by the name of the
derived type.

If you want something named To_T_Client_Name then of course you have to define
it yourself:

function To_T_Client_Name (S : String ) return T_Client_Name renames
To_Bounded_String;

The following compiles:

with Ada.Strings.Bounded;

procedure BS_Test is
   package BS is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type OS is new BS.Bounded_String;

   B : OS     := To_Bounded_String ("asdfghjkl");
   S : String := To_String (B);
begin -- BS_Test
   null;
end BS_Test;

-- 
Jeff Carter
"When Roman engineers built a bridge, they had to stand under it
while the first legion marched across. If programmers today
worked under similar ground rules, they might well find
themselves getting much more interested in Ada!"
Robert Dewar
62

^ permalink raw reply	[relevance 6%]

* Re: Bounded String question
  2015-11-11 10:52  0%   ` Serge Robyns
  @ 2015-11-11 15:41  0%     ` Bob Duff
  1 sibling, 0 replies; 200+ results
From: Bob Duff @ 2015-11-11 15:41 UTC (permalink / raw)


Serge Robyns <serge.robyns@gmail.com> writes:

> Hi Bob,
>
> On Wednesday, 11 November 2015 01:48:43 UTC+1, Bob Duff  wrote:
>> How about:
>> 
>>    function No_Client_Name return T_Client_Name is
>>       (T_Client_Name (P_Strings.Null_Bounded_String));
>
> May idea was to have a "constant" and use language construct/semantic to expose
> that.  I was expecting that the compiler will have more optimization options
> with such a construct than a dynamic construct like above.

I doubt that.  Especially if you put Inline.

>> But why do you need Preelaborate?  It's not all that much use if you use
>> GNAT's static elaboration model.
>
> Just for the sake of "cleanness" and again using language features to express
> my intent as per my "expectations".  Even if I would end up using GNAT in all
> cases.

One possibility is to use the option in GNAT that tells you where to put
pragma Elaborate_All, and put them in by hand.  Then you don't need
Preelaborate.

>> > Maybe I'm using bounded strings completely wrong.
>> 
>> Well, I think the Ada.Strings.Bounded package is way overengineered.
>> So "using Ada.Strings.Bounded" = "using bounded strings wrong".  ;-)
>> I suggest rolling your own.  No need for generics.
>> 
>>    type Bounded_String (Max_Length : Natural := ...) is limited record
>>       Length : Natural := 0;
>>       Chars  : String (1 .. Max_Length);
>>    end record;
>> 
>> along with a few trivial operations.
>
> I tend to agree that the bounded strings seems over-engineered but I'm lacking
> Ada experience to judge that properly.  However it is indeed a pain to use
> compared to other languages where I come from, e.g. C.  I don't know why
> strings are so complex to use in Ada. At various places I've conversions
> between bounded strings and plain strings in order to offer a consistent API to
> my modules. Luckily the package already provide a To_String function.  However,
> I've had to write loads of functions like "To_Client_Name (Name : in String)
> return T_Client_Name is (T_Client_Name (P_Strings.To_Bounded_String (Name));"
> as I haven't found a more direct way to convert a string to the type.

Can't you call the inherited To_Bounded_String directly?

>...This with
> some other oddities in Ada is what do give me a lot of frustrations.  However,
> I do remain decided to proceed with Ada, as I do believe in its core principles
> of allowing developing reliable software.
>
> Now with regards to rolling my own, is this not defeating re-use?  Why shall I
> waste my time on such a feature while I'm having loads of things to do on the
> application itself.

I'm all for reuse.  But in this case, the thing you're reusing causes a
fair amount of trouble, and rolling your own using the type I showed
above is trivial.

> I've been considering using unbounded strings instead but then I'm dropping the
> idea of a bounded storage for my entities.  Most of these "strings" ends up in
> record types which in the end will map to database entities.

Right, if you don't have a known bound, and you're not developing for a
small embedded system, then unbounded strings are often appropriate.
Those are complicated enough that I would not recommend rolling your
own.

Another alternative is Ada.Containers.Vectors instantiated with
Character.

- Bob


^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-11  0:48  7% ` Bob Duff
@ 2015-11-11 10:52  0%   ` Serge Robyns
    2015-11-11 15:41  0%     ` Bob Duff
  0 siblings, 2 replies; 200+ results
From: Serge Robyns @ 2015-11-11 10:52 UTC (permalink / raw)


Hi Bob,

On Wednesday, 11 November 2015 01:48:43 UTC+1, Bob Duff  wrote:
> How about:
> 
>    function No_Client_Name return T_Client_Name is
>       (T_Client_Name (P_Strings.Null_Bounded_String));

May idea was to have a "constant" and use language construct/semantic to expose that.  I was expecting that the compiler will have more optimization options with such a construct than a dynamic construct like above.
 
> But why do you need Preelaborate?  It's not all that much use if you use
> GNAT's static elaboration model.

Just for the sake of "cleanness" and again using language features to express my intent as per my "expectations".  Even if I would end up using GNAT in all cases.

> > Maybe I'm using bounded strings completely wrong.
> 
> Well, I think the Ada.Strings.Bounded package is way overengineered.
> So "using Ada.Strings.Bounded" = "using bounded strings wrong".  ;-)
> I suggest rolling your own.  No need for generics.
> 
>    type Bounded_String (Max_Length : Natural := ...) is limited record
>       Length : Natural := 0;
>       Chars  : String (1 .. Max_Length);
>    end record;
> 
> along with a few trivial operations.

I tend to agree that the bounded strings seems over-engineered but I'm lacking Ada experience to judge that properly.  However it is indeed a pain to use compared to other languages where I come from, e.g. C.  I don't know why strings are so complex to use in Ada. At various places I've conversions between bounded strings and plain strings in order to offer a consistent API to my modules. Luckily the package already provide a To_String function.  However, I've had to write loads of functions like "To_Client_Name (Name : in String) return T_Client_Name is (T_Client_Name (P_Strings.To_Bounded_String (Name));" as I haven't found a more direct way to convert a string to the type. This with some other oddities in Ada is what do give me a lot of frustrations.  However, I do remain decided to proceed with Ada, as I do believe in its core principles of allowing developing reliable software.

Now with regards to rolling my own, is this not defeating re-use?  Why shall I waste my time on such a feature while I'm having loads of things to do on the application itself.

I've been considering using unbounded strings instead but then I'm dropping the idea of a bounded storage for my entities.  Most of these "strings" ends up in record types which in the end will map to database entities.

> - Bob

Serge

^ permalink raw reply	[relevance 0%]

* Re: Bounded String question
  2015-11-10 22:00  6% Bounded String question Serge Robyns
@ 2015-11-11  0:48  7% ` Bob Duff
  2015-11-11 10:52  0%   ` Serge Robyns
  0 siblings, 1 reply; 200+ results
From: Bob Duff @ 2015-11-11  0:48 UTC (permalink / raw)


Serge Robyns <serge.robyns@gmail.com> writes:

>    No_Client_Name : constant T_Client_Name;

How about:

   function No_Client_Name return T_Client_Name is
      (T_Client_Name (P_Strings.Null_Bounded_String));

?

But why do you need Preelaborate?  It's not all that much use if you use
GNAT's static elaboration model.

> Maybe I'm using bounded strings completely wrong.

Well, I think the Ada.Strings.Bounded package is way overengineered.
So "using Ada.Strings.Bounded" = "using bounded strings wrong".  ;-)
I suggest rolling your own.  No need for generics.

   type Bounded_String (Max_Length : Natural := ...) is limited record
      Length : Natural := 0;
      Chars  : String (1 .. Max_Length);
   end record;

along with a few trivial operations.

- Bob


^ permalink raw reply	[relevance 7%]

* Bounded String question
@ 2015-11-10 22:00  6% Serge Robyns
  2015-11-11  0:48  7% ` Bob Duff
  0 siblings, 1 reply; 200+ results
From: Serge Robyns @ 2015-11-10 22:00 UTC (permalink / raw)


I'm trying to use bounded strings and I'm facing some issues when I'm trying to use pragma preelaborate in my package.

I'm using bounded strings to store some text data with an upper limit in size.  I've been a little lazy and I'm reusing the same package for different "types".  But I do want to have the different types to be different, so that they cannot be assigned to each other for example.

package Test is
   -- pragma Preelaborate;
   package P_Strings is new Ada.Strings.Bounded.Generic_Bounded_Length (20);

   type T_Client_Name is new P_Strings.Bounded_String;
   type T_Account_Name is new P_Strings.Bounded_String;

....

   No_Client_Name : constant T_Client_Name;
   No_Account_Name : constant T_Account_Name;
...
private
   No_Client_Name : constant T_Client_Name := T_Client_Name (P_Strings.Null_Bounded_String);
   No_Account_Name : constant T_Account_Name := T_Account_Name (P_Strings.Null_Bounded_String);
...

Everything works fine as long as I don't want to use the pragma preelaborate.

When compiling with pragma preelaborate I get the following errors.
non-static constant in preelaborated unit
static expression must have scalar or string type (RM 4.9(2))

I've been trying to find solutions and so far the only one that seems not to complain is when I'm create subtypes and using renames to rename P_Strings.Null_Bounded_String as for example:
subtype T_Client_Name is P_Strings.Bounded_String;
No_Client_Name : T_Client_Name renames P_Strings.Null_Bounded_String; 

However this is defeating my initial purpose of using types.  Because now I can mix T_Client_Name and T_Account_Name, which is now "legal" but makes no sense in my application.

I've been trying to use pragma Preelaborable_Initialization (T_Client_Name) but this seems not to solve it.

Maybe I'm using bounded strings completely wrong.

Some advise is most welcome.


^ permalink raw reply	[relevance 6%]

* Re: What do you think about this?
  2015-06-23 19:51  4%             ` Laurent
@ 2015-06-23 20:20  0%               ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2015-06-23 20:20 UTC (permalink / raw)


On Tuesday, June 23, 2015 at 12:51:08 PM UTC-7, Laurent wrote:
> On Tuesday, 23 June 2015 16:21:17 UTC+2, Stephen Leake  wrote:
> > I did not download and compile it, but I did browse around it a bit.
> 
> That's why I like git.
> 
> with Ada.Strings.Bounded;
> with Ada.Strings.Fixed;
> 
> package Common_Defs_BCI is
> 
>    V_String_Length  : constant :=  64;
> 
>    package V_String is new
>      Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);
> 
>    function "+" (Right : V_String.Bounded_String) return String
>                  renames
>      V_String.To_String;
> 
>    function "+" (Right : String) return V_String.Bounded_String
>    is (V_String.To_Bounded_String (Right));
> 
>    function Trim (Right : String) return V_String.Bounded_String is
>      (V_String.To_Bounded_String (Ada.Strings.Fixed.Trim (Right, Ada.Strings.Both)));
> 
> end Common_Defs_BCI;

I would suggest to improve the last two functions with the following preconditions. That means any attempt to pass an String whose length is longer than 40 characters will be slapped by the run time.

   --...
   with pre => Right <= V_String_Length;

Anh Vo
 

^ permalink raw reply	[relevance 0%]

* Re: What do you think about this?
  @ 2015-06-23 19:51  4%             ` Laurent
  2015-06-23 20:20  0%               ` Anh Vo
  0 siblings, 1 reply; 200+ results
From: Laurent @ 2015-06-23 19:51 UTC (permalink / raw)


On Tuesday, 23 June 2015 16:21:17 UTC+2, Stephen Leake  wrote:
> I did not download and compile it, but I did browse around it a bit.

That's why I like git.

> The code looks clean and well-organized,

Ok that is already a good thing to hear.

>What is the whole thing supposed to do?

It is supposed to generate something like this:

mtrsl|pi12345678910|p2164|pp907088|p5907088|si|s040330|ssPLAIES|s5PLAIES|ci501502240387|c040330|ctAERO|ta|rtAST-N264|rr10335191|t12|o1esccol|ra|a1tem|a3<=4|a4S|ra|a1am|a34|a4S|ra|a1amc|a34|a4S|ra|a1tzp|a3<=4|a4S|ra|a1rox|a34|a4S|ra|a1tax|a3<=1|a4S|ra|a1taz|a3<=1|a4S|ra|a1fep|a3<=1|a4S|ra|a1etp|a3<=0,5|a4S|ra|a1mem|a3<=0,25|a4S|ra|a1an|a3<=2|a4S|ra|a1gm|a3<=1|a4S|ra|a1cip|a3<=0,25|a4S|ra|a1lev|a3<=0,12|a4S|ra|a1tgc|a3<=0,5|a4S|ra|a1fos|a3<=16|a4S|ra|a1ftn|a3<=16|a4S|ra|a1sxt|a3<=20|a4S|zz|

And then write it in a text file. 

The hospital I work for has acquired a new software for epidemical surveillance. I work in the lab in the microbiology department and I have been asked to verify the transmission of the results from the analyzer to the software used by the nurses/docters. 

I have 3 possibilities to do that:

1) launch tests but that takes 24hrs and I have no influence on the result
2) use existing tests and rename them. Which means I have to tinker around with results of actual patients. Is bad because of the iso certification which requires everything to be traceable. No influence on the result
3) write a program which generates textfiles with random results which I can copy into the transfer folder on the analyzer. 

> What is a "antibiogramme"?

The analyzer is testing the susceptibility of a bacteria against a number of antibiotics. The whole result is called an antibiogramme. 

The CMI (MIC in english) is the "minimum inhibitory concentration" that is the lowest concentration of the antibiotic required to kill 99.9% of the bacteria. 

There are breakpoints for every antibiotic which define if it is S = sensible, I = intermediate (could work) or R = resistant. That is called the susceptibility.

> What is a "dossier"?

medical file in this case. I am used to the french names of the whole stuff so I used them everywhere.

>but it lacks comments

Yup something I have to improve. In this case the program is only used by me and quite probable only once. As well as a todo list so that I remember where I left in the case I don't work on a project for longer time.

> There are cases where a function returns a V_String but could return a
> plain String; in general, unless the result _must_ be a V_String for
> some reason, it is better to return a String; then the caller can just
> use it without conversion, or declare a local variable to hold it.

I have quite often problems with different string types and their behavior. So I followed  Bruce B's
recommendation (some earlier post: "Annoying behavior") to make a package:

with Ada.Strings.Bounded;
with Ada.Strings.Fixed;

package Common_Defs_BCI is

   V_String_Length  : constant :=  64;

   package V_String is new
     Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);

   function "+" (Right : V_String.Bounded_String) return String
                 renames
     V_String.To_String;

   function "+" (Right : String) return V_String.Bounded_String
   is (V_String.To_Bounded_String (Right));

   function Trim (Right : String) return V_String.Bounded_String is
     (V_String.To_Bounded_String (Ada.Strings.Fixed.Trim (Right, Ada.Strings.Both)));

end Common_Defs_BCI;

So no more confusion with different string types. 

>... it is better to return a String; then the caller can just use it without conversion, or declare a >local variable to hold it.

Well without the "+" conversion function I would agree because the To_Bound... thing is annoying.
For the last part I don't understand what you mean. In the main file I have the function Make_File_Name where File_Name is local variable. If it is of type String or the custom V_String, where is the difference? Ok I have to convert it later in procedure Generate. Requires an additional "+". I find it is a quite good tradeoff for the flexibility it offers me. 

If you have an example where you think that it is not recommended I'd like to see. I have of course no idea how expensive that is in terms of computation power.

   function Make_File_Name (How_Many : in Positive) return V_String.Bounded_String is

      File_Name : V_String.Bounded_String;

      Right_Now : Ada.Calendar.Time := Ada.Calendar.Clock;...

   begin
     ...
      File_Name := +("VITEK2-BCI_" &...;
      return File_Name;
   end Make_File_Name;

 procedure Generate (How_Many : in Positive) is

      File : Ada.Text_IO.File_Type;
   begin -- Generate
      for Counter in 1 .. How_Many loop

         declare
--  removed the declaration of the different objects
         begin -- declare
            Ada.Text_IO.Create (File => File,
                                Mode => Ada.Text_IO.Out_File,
                                Name => +Make_File_Name (Counter)); <---

            BCI_Messages.IO.To_BCI (Item => Test_Message, File => File);
            Ada.Text_IO.Close (File);
         end; -- declare
      end loop;
   end Generate;

For the CMI I would have preferred to use enumerations but that doesn't seem to be possible:

CMI_Type is ("<=1","0,004","3"); or CMI_Type is ("1","2","3"); 

but that works CMI_Type is ('1','2','3'); ?

For the SIR I have used an enumeration at the beginning but I had some problems getting the result written to the text file. So the V_String solved most of the problems.

I have to wait for the person which takes care of the informatics in the lab before I inject the text files into the analyzer. Would be stupid to blow up the online connections with an ill formatted result and no one there to restore them.

Thanks Stephen for your time and comments.

Laurent


^ permalink raw reply	[relevance 4%]

* Re: Textedit and txt
  2015-05-07 21:12  6%             ` Laurent
@ 2015-05-09 15:23  0%               ` brbarkstrom
  0 siblings, 0 replies; 200+ results
From: brbarkstrom @ 2015-05-09 15:23 UTC (permalink / raw)


On Thursday, May 7, 2015 at 5:12:29 PM UTC-4, Laurent wrote:
> On Wednesday, May 6, 2015 at 11:23:36 PM UTC+2, Randy Brukardt wrote:
> 
> Hi
> 
> I tried to put that package together but I get this error on the second function:
> 
>         14:4 no visible subprogram matches the specification for "+"
>         14:4 missing specification for "Drop"
> 
> 
> with Ada.Strings.Bounded;
> 
> package Common_Defs is
> 
>    V_String_Length  : constant :=  256;
> 
>    package V_String is new
>      Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);
> 
>    function "+" (Right : V_String.Bounded_String) return String
>    renames
>      V_String.To_String;
> 
>    function "+" (Right : String) return V_String.Bounded_String
>    ^----- error
>    renames
>      V_String.To_Bounded_String;
> 
> end Common_Defs;
> 
> I have no idea what the compiler is complaining about.
> 
> > Note that some people hate using "+" this way, because they think it has 
> > something to do with numerics. We really should have something non-specific 
> > (say an operator "#"), but the ARG is always split between people that think 
> > we already have such an operator ("+") and thus we don't need another one 
> > and those that are repulsed by using "+" this way. (Getting these put into 
> > the packages themselves failed for similar reasons. Grumble.)
> 
> Well if it makes life easier why not use it. And if someone does't like to use a '+' then take something else, as long as you remember what it is doing.
> 
> >I'd prefer a completely different design for both of these packages, so we could add some >mechanism to allow direct conversions, but that's likely too radical.) 
> 
> Why would that be too radical?
> 
> Thanks
> 
> Laurent

Sorry to go back in the thread.  However, instead of creating a new
symbol '+' to indicate append, it might be easier to consult the Ada
RM.  In section A.4.4 of the Ada 2012 RM, there are a number of overloaded
functions specifically called 'Append'.  Furthermore, the second page of this 
section specifically uses '&' as an append operator.  Since these two 
constructions are already part of the package `Bounded_String', it isn't clear 
what we gain by using a variant construction.

Bruce B.


^ permalink raw reply	[relevance 0%]

* Re: Textedit and txt
  2015-05-06 21:23  0%           ` Randy Brukardt
@ 2015-05-07 21:12  6%             ` Laurent
  2015-05-09 15:23  0%               ` brbarkstrom
  0 siblings, 1 reply; 200+ results
From: Laurent @ 2015-05-07 21:12 UTC (permalink / raw)


On Wednesday, May 6, 2015 at 11:23:36 PM UTC+2, Randy Brukardt wrote:

Hi

I tried to put that package together but I get this error on the second function:

        14:4 no visible subprogram matches the specification for "+"
        14:4 missing specification for "Drop"


with Ada.Strings.Bounded;

package Common_Defs is

   V_String_Length  : constant :=  256;

   package V_String is new
     Ada.Strings.Bounded.Generic_Bounded_Length (V_String_Length);

   function "+" (Right : V_String.Bounded_String) return String
   renames
     V_String.To_String;

   function "+" (Right : String) return V_String.Bounded_String
   ^----- error
   renames
     V_String.To_Bounded_String;

end Common_Defs;

I have no idea what the compiler is complaining about.

> Note that some people hate using "+" this way, because they think it has 
> something to do with numerics. We really should have something non-specific 
> (say an operator "#"), but the ARG is always split between people that think 
> we already have such an operator ("+") and thus we don't need another one 
> and those that are repulsed by using "+" this way. (Getting these put into 
> the packages themselves failed for similar reasons. Grumble.)

Well if it makes life easier why not use it. And if someone does't like to use a '+' then take something else, as long as you remember what it is doing.

>I'd prefer a completely different design for both of these packages, so we could add some >mechanism to allow direct conversions, but that's likely too radical.) 

Why would that be too radical?

Thanks

Laurent



^ permalink raw reply	[relevance 6%]

* Re: Textedit and txt
  2015-04-26 13:21  4%         ` brbarkstrom
@ 2015-05-06 21:23  0%           ` Randy Brukardt
  2015-05-07 21:12  6%             ` Laurent
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2015-05-06 21:23 UTC (permalink / raw)


<brbarkstrom@gmail.com> wrote in message 
news:51c639dd-a48c-4130-becd-750cb23094da@googlegroups.com...
On Sunday, April 26, 2015 at 7:52:05 AM UTC-4, Laurent wrote:
>> Thanks for the hint. Why hide that in the preferences? Apple has 
>> sometimes strange ideas. Terminal an pico works too. Not really a fan of 
>> emacs/aquamacs. Tried once to learn mozart oz as language and they used 
>> emacs as ide. Didn't really work for me so I gave up.

>I'd suggest taking a look at the Reference Manual section on
>the Bounded_Strings package.  You can create a default Bounded_String
>length in a package (say named Common_Defs.ads) using
>
>  Std_Vstring_Length  : constant :=  256;
>  package VString     is new
>    Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);

On top of this suggestion, I'd suggest defining the conversion operator (AKA 
unary plus) appropriately:

   function "+" (Right : VString.Bounded_String) return String renames 
VString.To_String;
   function "+" (Right : String) return VString.Bounded_String renames 
VString.To_Bounded_String;

Then you can write:

         Ada.Text_IO.Put_Line ("read code: "
                               & (+Temp_Record.Code_SIL));

instead of:

         Ada.Text_IO.Put_Line ("read code: "
                               & Codes.To_String (Temp_Record.Code_SIL));

Note that some people hate using "+" this way, because they think it has 
something to do with numerics. We really should have something non-specific 
(say an operator "#"), but the ARG is always split between people that think 
we already have such an operator ("+") and thus we don't need another one 
and those that are repulsed by using "+" this way. (Getting these put into 
the packages themselves failed for similar reasons. Grumble.)

In any case, I think Bounded_String and Unbounded_String are unusable 
without these definitions. So you either have to swallow "+" or forget the 
packages altogether. Neither is appealing. (I'd prefer a completely 
different design for both of these packages, so we could add some mechanism 
to allow direct conversions, but that's likely too radical.)

                                   Randy.


^ permalink raw reply	[relevance 0%]

* Re: Textedit and txt
  @ 2015-04-26 13:21  4%         ` brbarkstrom
  2015-05-06 21:23  0%           ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: brbarkstrom @ 2015-04-26 13:21 UTC (permalink / raw)


On Sunday, April 26, 2015 at 7:52:05 AM UTC-4, Laurent wrote:
> Thanks for the hint. Why hide that in the preferences? Apple has sometimes strange ideas. Terminal an pico works too. Not really a fan of emacs/aquamacs. Tried once to learn mozart oz as language and they used emacs as ide. Didn't really work for me so I gave up.

I'd suggest taking a look at the Reference Manual section on
the Bounded_Strings package.  You can create a default Bounded_String
length in a package (say named Common_Defs.ads) using

  Std_Vstring_Length  : constant :=  256;
  package VString     is new
    Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);

Then, you just with and use Common_Defs.  When you want to create 
a new Bounded_String, you define

  S : Vstring.Bounded_String;

then, when you want to put characters into the string, you can put

  S := Vstring.To_Bounded_String("whatever");

with that, you can append, as in

  S := Vstring.Append(S, " and something else");

get the length of the string

  Length_Of_String := Natural(Vstring.Length(S));

and so on.

This isn't really complicated, although my natural coding style is
quite verbose.  If you use this approach, you should be able to stop
worrying about whether you're working with an Apple or some other kind
of machine.  It's already part of the standard Ada packages.

Bruce B.


^ permalink raw reply	[relevance 4%]

* Re: How to get nice with GNAT?
  @ 2014-11-24  3:05  5%     ` brbarkstrom
  0 siblings, 0 replies; 200+ results
From: brbarkstrom @ 2014-11-24  3:05 UTC (permalink / raw)


On Sunday, November 23, 2014 3:49:38 PM UTC-5, Jeffrey Carter wrote:
> On 11/23/2014 10:41 AM, brbarkstrom wrote:
> > 
> > I'm working in GNAT GPL, so my suggestion may not work with every
> > compiler.
> > 
> > On the other hand, in my code, the if following the exception in the
> > procedure is picked up and executed properly.  The code doesn't act
> > like the program has to fail if any exception is raised.
> 
> I don't think you're talking about exceptions. I took this program:
> 
> with Ada.Text_IO;
> procedure Boolean_Exception is
>    procedure Test (OK : out Boolean) is
>       -- empty declarative part
>    begin -- Test
>       OK := False;
> 
>       raise Constraint_Error;
>    end Test;
> 
>    OK : Boolean := True;
> begin -- Boolean_Exception
>    Test (OK => OK);
>    Ada.Text_IO.Put_Line (Item => "No exception");
> exception -- Boolean_Exception
> when others =>
>    Ada.Text_IO.Put_Line (Item => Boolean'Image (OK) );
> end Boolean_Exception;
> 
> compiled with GNAT 4.6 on Linux, and got:
> 
> $ gnatmake -gnatwa -gnatano -O2 -fstack-check boolean_exception.adb
> gcc-4.6 -c -gnatwa -gnatano -O2 -fstack-check boolean_exception.adb
> boolean_exception.adb:6:10: warning: assignment to pass-by-copy formal may have
> no effect
> boolean_exception.adb:6:10: warning: "raise" statement may result in abnormal
> return (RM 6.4.1(17))
> gnatbind -x boolean_exception.ali
> gnatlink boolean_exception.ali -O2 -fstack-check
> $ ./boolean_exception
> TRUE
> 
> What you're talking about doesn't work with GNAT.
> 
> -- 
> Jeff Carter
> "This school was here before you came,
> and it'll be here before you go."
> Horse Feathers
> 48

Here's a rather long response to your post:

I don't think you'll get a sensible response when you try to set
Test(OK => True); or Test(OK => False) when the specification of
the procedure Test has OK as an "out" variable.  It doesn't make 
sense try to set this value as input to a variable that emerges from the procedure (Test).

Here's a slight rewriting of the code you provided:

with Ada.Text_IO;
procedure exception_handling_0 is

   procedure test (OK : out Boolean) is
      -- empty declarative part
   begin -- test
      OK := False;
      raise Constraint_Error;
   end test;

   OK : Boolean := True;

begin -- exception_handling_0
   test (OK => OK);
   Ada.Text_IO.Put_Line (Item => "No exception");

exception
   when others =>
      Ada.Text_IO.Put_Line (Item => Boolean'Image (OK) );
end exception_handling_0;

The GNAT GPL GPS tool on my Ubuntu 14.04 LTS system returns the
two warnings:
7.10     warning: assignment to pass-by-copy formal may have no effect
7.10     warning: "raise" statement may result in abnormal return
           (RM 6.4.1(17))

In other words, a programmer shouldn't expect a variable input to
an "out" variable in the interface specification to have any relation
to whatever is generated in the procedure that is called.  Secondly,
an exception raised in the procedure test may result in an abnormal
return.  This is hardly a clean piece of code. 

When I run it, the output from the code does something that seems
to me to be an abnormal return.  It returns the output "TRUE".
The output claims that "the process terminated successfully, ...".  
It certainly isn't the expected behavior in a reasonable reading of the 
procedure text.  Rather it suggests that the compiler completely ignored
whatever went on in the procedure.

Putting the same code into a Windows XP installation of GNAT GPL 2014 with GPS
produces exactly the same warnings, compilation, and output.

In the original source code I provided, I used the following specification
file (called Common_Defs.ads):

with Ada.Characters.Latin_1;
with Ada.Strings;
with Ada.Strings.Bounded;
with Ada.Numerics;
with Ada.Numerics.generic_elementary_functions;

package Common_Defs is
  ------------------------------------------------------------------------------
  -- Generic Packages
  ------------------------------------------------------------------------------
  subtype real        is long_float;
  package Usr_Math    is new
                        Ada.Numerics.generic_elementary_functions(real);
  Std_Vstring_Length  : constant :=  256;
  package VString     is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);
  Long_Vstring_Lngth  : constant := 5000;
  package Long_Vstring is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Long_Vstring_Lngth);
  ------------------------------------------------------------------------------
  -- Constant
  ------------------------------------------------------------------------------
   TAB                         : constant Character := Ada.Characters.Latin_1.HT;
end Common_Defs;

Then, I created the source code

with Ada.Text_IO;
with Common_Defs; use Common_Defs;
procedure Test_Exception is

   -- Local Procedure Specification
   procedure Test (I       : in     Natural;
                   OK      :    out Boolean;
                   Err_Msg :    out Vstring.Bounded_String);

   -- Variables
   I       : Natural := 20;
   Test_OK : Boolean;
   Err_Msg : Vstring.Bounded_String;

   -- Local Procedure Body
   procedure Test (I       : in     Natural;
                   OK      :    out Boolean;
                   Err_Msg :    out Vstring.Bounded_String) is
      Max_I          : Natural := 10;
      I_Out_Of_Range : exception;      
   begin -- Test
      OK := False;
      Err_Msg := Vstring.To_Bounded_String("procedure Test was not initialized when this message was created.");
      if I <= Max_I then
         OK := True;
         Err_Msg := Vstring.To_Bounded_String("In procedure Test, I as input : ");
         Err_Msg := Vstring.Append(Err_Msg, Natural'image(I));
         Err_Msg := Vstring.Append(Err_Msg, " was less than or equal to ");
         Err_Msg := Vstring.Append(Err_Msg, Natural'image(Max_I));
      else
         raise I_Out_Of_Range;
      end if;
   exception
      when I_Out_Of_Range =>
         Err_Msg := Vstring.To_Bounded_String("In procedure Test, I as input : ");
         Err_Msg := Vstring.Append(Err_Msg, Natural'image(I));
         Err_Msg := Vstring.Append(Err_Msg, " was greater than ");
         Err_Msg := Vstring.Append(Err_Msg, Natural'image(Max_I));
         Err_Msg := Vstring.Append(Err_Msg, " which raises the constraint 'I_Out_Of_Range'.");
      when others =>
         Err_Msg := Vstring.To_Bounded_String("In procedure Test, something unexpected happened.");
   end Test;

begin -- Test_Exception
   Test (I       => 25,
         OK      => Test_OK,
         Err_Msg => Err_Msg);
   if Test_OK then
      Ada.Text_IO.Put_Line(Vstring.To_String(Err_Msg));
   else
      Ada.Text_IO.Put_Line(Vstring.To_String(Err_Msg));
   end if;
end Test_Exception; 

On Windows, this compiles without warnings.  After compilation, binding, and linking, it
runs and outputs the message 
"In procedure Test, I as input :  25 was greater than  10 which raises the constraint 'I_Out_Of_Range'."  It is clear that the initial setting of
OK and Err_Msg in the procedure have been changed as a result of the
operations during execution.

The behavior on the Ubuntu Linux 64-bit installation of GNAT GPL is identical.

My conclusions:

1.  One should not call a procedure to input an "out" variable as declared in the spec and
expect it to return values from the interior of the procedure.  In this code, the exception is not one of the system exceptions.
Rather, it is one declared normally in accord with the RM (11.1).  An exception handler follows the
specification in RM (11.2), where the Examples at the end of this definition show an approach
that the code I've provided follows.

2.  The handled sequence of statements allow variables set as "out" in the procedure specification
to appear as legitimate values (even using the "pass-by-copy" rule).  Thus, these "out" variables
can guide procedure actions for the calling procedure even when the called
procedure throws an exception.

Bruce B.


^ permalink raw reply	[relevance 5%]

* Re: array of string
    2014-10-07  1:06  5% ` brbarkstrom
@ 2014-10-07 16:49  7% ` brbarkstrom
  1 sibling, 0 replies; 200+ results
From: brbarkstrom @ 2014-10-07 16:49 UTC (permalink / raw)


On Friday, October 3, 2014 7:29:15 PM UTC-4, Stribor40 wrote:
> is there way to declare array of strings to contain something like this..
> 
> 
> 
> a(1)="london"
> 
> a(2)""toronto"
> 
> 
> 
> how would i create this?

Constantly.  It's a habit now.  One advantage is the Bounded_Strings
library in the ARM.  It has functions for appending strings, extracting slices,
obtaining single characters, and so on.  I've created a package I call
Common_Defs.ads that lets me have a moderately long string (256 characters)
and a very long one (5000 characters).  Note also that the Bounded_String
library throws an exception if you try to stuff too many characters into
the string.  That provides a reasonable way to filter out strings that could
cause buffer overflows in Web page text inputs.

Here's the code:

with Ada.Characters.Latin_1;
with Ada.Strings;
with Ada.Strings.Bounded;
with Ada.Numerics;
with Ada.Numerics.generic_elementary_functions;

package Common_Defs is
  ------------------------------------------------------------------------------
  -- Generic Packages
  ------------------------------------------------------------------------------
  subtype real        is long_float;
  package Usr_Math    is new
                        Ada.Numerics.generic_elementary_functions(real);
  Std_Vstring_Length  : constant :=  256;
  package VString     is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);
  Long_Vstring_Lngth  : constant := 5000;
  package Long_Vstring is new
                        Ada.Strings.Bounded.Generic_Bounded_Length(Long_Vstring_Lngth);
  ------------------------------------------------------------------------------
  -- Constant
  ------------------------------------------------------------------------------
   TAB                         : constant Character := Ada.Characters.Latin_1.HT;
end Common_Defs;

This package spec lets me create long_floats and bring along the appropriate
math functions in one fell swoop.  If using the compiler default on long_floats
worries you, you can define the numerical type you want and embed it in this
kind of spec.  The reason for having the TAB character is if you want to 
create TAB-delimited text files that you can feed into spreadsheets.  If you
do the usual 

with Common_Defs; use Common_Defs;

then you can just use Put(TAB) (or Put(Output_File, TAB)) in Text_IO 
interactions.

Bruce B.

^ permalink raw reply	[relevance 7%]

* Re: array of string
  @ 2014-10-07  1:06  5% ` brbarkstrom
  2014-10-07 16:49  7% ` brbarkstrom
  1 sibling, 0 replies; 200+ results
From: brbarkstrom @ 2014-10-07  1:06 UTC (permalink / raw)


On Friday, October 3, 2014 7:29:15 PM UTC-4, Stribor40 wrote:
> is there way to declare array of strings to contain something like this..
> 
> 
> 
> a(1)="london"
> 
> a(2)""toronto"
> 
> 
> 
> how would i create this?

You could also create an array of Bounded_Strings.  When you set up such
an array, you can specify the maximum size.  Then when you assign a particular
array element, you use the Bounded_Strings package functions to assign a
string to the array.  In other words, you can write

Std_Vstring_Length : constant := 256;
package Vstring is new Ada.Strings.Bounded.Generic_Bounded_Length(Std_Vstring_Length);

Then you should be able to define

Max_Array_Size : constant := 10; -- or whatever the number of strings you want
Bounded_String_Array : array (1 .. Max_Array_Size) of Vstring.Bounded_String;

later, you can do things like

Bounded_String_Array(1) := Vstring.To_Bounded_String("london");
Bounded_String_Array(2) := Vstring.To_Bounded_String("toronto");

If you want to print the strings, you can do things like

Text_IO.Put(Vstring.To_String(Bounded_String_Array(1)));

which should output just london

while 

Text_IO.Put_Line(Vstring.To_String(Bounded_String_Array(2)));

would ouput toronto on a single line.

There are a number of useful functions, including Slice and Element
in the Bounded_Strings package.  You can even use Direct_IO to 
save the elements of the array Bounded_String_Array so you can
retrieve them by doing 

package Bounded_String_DIO is new Direct_IO(Bounded_String_Array); use Bounded_String_DIO;

Then you can do things like

Bounded_String_DIO.Write(File => Bounded_String_DIO_File,
                         Item => Bounded_String_Array(4),
                         To   => Bounded_String.Positive_Count(4));

and read it with

Bounded_String_DIO.Read(File => Bounded_String_DIO_File,
                        Item => Selected_Bounded_String,
                        From => Bounded_String.Positive_Count(4));

which will read the Bounded_String_Array element 4 into 

Selected_Bounded_String : Vstring.Bounded_String;

Hope this helps.

Bruce B.


^ permalink raw reply	[relevance 5%]

* Re: Warning: Storage error
  2014-08-09 16:26  5%   ` Dmitry A. Kazakov
@ 2014-08-09 16:46  6%     ` Jeffrey Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey Carter @ 2014-08-09 16:46 UTC (permalink / raw)


On 08/09/2014 09:26 AM, Dmitry A. Kazakov wrote:
>
> Ada.Strings.Bounded is practically unusable. Unbounded_String offers no
> advantage over custom type because it requires explicit conversion to
> String, and is suspicious for allocating more memory in advance than
> actually required. RM is silent about the memory usage strategy.

I agree that Ada.Strings.Bounded has a poor interface. I rarely use it. But when 
I do need bounded strings, I find the advantages of reuse usually outweight the 
disadvantages of the poor interface.

Using the standard library has the advantages of being more likely to be 
correct, requiring less development effort, and being easier for future readers 
to understand.

If you're worried about the implementation of an abstraction in the standard 
library in absence of any evidence that it is responsible for being unable to 
meet your requirements then you probably shouldn't be using Ada. Ada (and 
software engineering) is largely about abstraction and not worrying about 
implementations unless one has to.

-- 
Jeff Carter
"Insufficient laughter--that's grounds for divorce."
Play It Again, Sam
126

^ permalink raw reply	[relevance 6%]

* Re: Warning: Storage error
  2014-08-09 16:08  5% ` Jeffrey Carter
@ 2014-08-09 16:26  5%   ` Dmitry A. Kazakov
  2014-08-09 16:46  6%     ` Jeffrey Carter
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2014-08-09 16:26 UTC (permalink / raw)


On Sat, 09 Aug 2014 09:08:54 -0700, Jeffrey Carter wrote:

> It also appears that you're attempting to reinvent Ada.Strings.Bounded.

A more frequent use case is a constant string allocated and initialized
once.

Ada.Strings.Bounded is practically unusable. Unbounded_String offers no
advantage over custom type because it requires explicit conversion to
String, and is suspicious for allocating more memory in advance than
actually required. RM is silent about the memory usage strategy.

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


^ permalink raw reply	[relevance 5%]

* Re: Warning: Storage error
  @ 2014-08-09 16:08  5% ` Jeffrey Carter
  2014-08-09 16:26  5%   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Jeffrey Carter @ 2014-08-09 16:08 UTC (permalink / raw)


On 08/09/2014 08:20 AM, Victor Porton wrote:
>     type My_String (Length: Integer := 0) is
>        record
>           Str: String(1..Length);
>        end record;
>
> warning: creation of "My_String" object may raise Storage_Error
>
> Why this warning?

There are 2 ways to implement such a type. One allocates just as much space as 
the current value (plus some small fixed overhead); the other allocates enough 
space for the largest value.

Some argue that Ichbiah intended the former, and there is at least one compiler 
that does it that way. It appears that you're using a compiler that uses the 
latter, and every such object will take at least Integer'Last bytes.

It also appears that you're attempting to reinvent Ada.Strings.Bounded.

-- 
Jeff Carter
"Insufficient laughter--that's grounds for divorce."
Play It Again, Sam
126

^ permalink raw reply	[relevance 5%]

* Re: trimming strings
  @ 2014-08-03 23:14  5%     ` Georg Bauhaus
  0 siblings, 0 replies; 200+ results
From: Georg Bauhaus @ 2014-08-03 23:14 UTC (permalink / raw)


On 03.08.14 23:42, agent@drrob1.com wrote:

> Procedure trimtest is
>    Subtype String255FixedType is String(1..255);
>
>    str    : String255Fixedtype;
>    STRLEN : Natural;
>
> BEGIN
>    Put(" Enter line: ");
>    Get_Line(Str,StrLen);
>    Str := TRIM(Str,Side => Both);
> --  Str := Ada.Strings.Fixed.TRIM(str,side => Ada.Strings.both);
>    Put_Line(" Line is: " & Str(1..StrLen) & " with length of " &
> Natural'image(StrLen) );
> End trimtest;
>
> This simple procedure compiles, but does give me an exception at
> run-time after I call trim.  I don't understand how to avoid this.  I
> am used to more flexible strings that are null terminated.

These are Ada.Strings.Bounded and Ada.Strings.Unbounded. Or,
if you want the greatest possible flexibility, wrap a pointer
to String in a type derived from Finalization.Controlled. This,
however, will likely turn into reinventing either of the former
language defined packages.

An object of type String255FixedType will always be what it is
by declaration: an array of exactly 255 components, indexed
by values between 1 and 255, inclusively. So, "fixed" is a
well chosen part of the subtype's name.

> How do I avoid a constraint_error exception at run-time?

One more way is to declare the string object where you need it

    Get_Line (Str, StrLen);
    declare
       Trimmed : String := Trim (Str(1 .. StrLen), Side => Both);
    begin
        ... do something with Trimmed
    end;

Or pass the trimmed result to some procedure that works on it:

    procedure Taking_Trimmed (S : String) is
       --  S is of any length, and of any indexing subtype
    begin
       -- note: S'Length, S'First, etc are known here
    end Taking_Trimmed;
    ...
    Get_Line (Str, StrLen);
    Taking_Trimmed (Trim (Str(1 .. StrLen), Side => Both));





^ permalink raw reply	[relevance 5%]

* Strange compile-time error  with Ada.Containers.Indefinite_Hashed_Maps
@ 2014-05-19 10:10  6% mockturtle
  0 siblings, 0 replies; 200+ results
From: mockturtle @ 2014-05-19 10:10 UTC (permalink / raw)


Dear all,
I am stuck with an error that could be a compiler bug and I hope you could give me some help.  I am currently using GNAT 20140331 on 64 bit Linux.

A brief introduction about what I am trying to do: I want to implement a "symbol table" that maps identifiers (implemented as bounded strings) into "symbol descriptors" (implemented as records with a discriminant that identifies the symbol type).  

I define the "identifier name" type in a package that is with-ed by the package that defines the symbol table.  The symbol table is just a Indefinite_Hash_Map (indefinite since the descriptor is indefinite).   When I try to compile the body of the symbol table package I get in the .ads the error 

    instantiation error at a-cihama.adb:1043
    invalid constraint: type has no discriminant

I was able to replicate the error with a small set of files.  At the end of this message you will find three packages: Ginger (that defines the identifier type), Foo (that with-s Ginger) and Foo_2 (that is Foo merged together with Ginger, so that it is self-sufficient).

If I try to compile foo.adb, I get the error above; if I try to compile foo-2.adb, I get no error.  This makes me suspect that (i) I tripped over some subtlety of the language or (ii) this is a bug.

Any help?

Thank you.

Riccardo

---------

--------------------
--   GINGER.ADS   --
--------------------

with Ada.Strings.Bounded;

package ginger is
   type Name_Type is private;

   function To_String(X:Name_Type) return String;

private
   package Names is
     new Ada.Strings.Bounded.Generic_Bounded_Length (10);

   type Name_Type is new Names.Bounded_String;

   function To_String (X : Name_Type) return String
   is (Names.To_String (Names.Bounded_String (X)));
end ginger;

-----------------
--   FOO.ADS   --
-----------------


with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with Ginger;

package foo is
   type My_Map is tagged private;

   type Name_Class is (First, Second);

   type Descriptor (Class : Name_Class) is
      record
         case Class is
            when First =>
               null;

            when Second =>
               X : Float;
         end case;
      end record;

   procedure Zizi (X: My_Map);

private
   function Hash (Key : Ginger.Name_Type) return Ada.Containers.Hash_Type;

   function Equal (Left, Right : Ginger.Name_Type) return Boolean;

   package Maps is
     new Ada.Containers.Indefinite_Hashed_Maps
       (Key_Type        => Ginger.Name_Type,
        Element_Type    => Descriptor,
        Hash            => Hash,
        Equivalent_Keys => Equal);

   type My_Map is  new Maps.Map with null record;
end foo;

-----------------
--   FOO.ADB   --
-----------------

package body foo is

   ----------
   -- Zizi --
   ----------

   procedure Zizi (X: My_Map) is
   begin
      null;
   end Zizi;
   
   function Hash (Key : Ginger.Name_Type) return Ada.Containers.Hash_Type
   is
   begin
      return Ada.Strings.Hash (Ginger.To_String (Key));
   end Hash;

   function Equal (Left, Right : Ginger.Name_Type) return Boolean 
   is
   begin
      
      return Ginger.To_String (Left) = Ginger.To_String (Right);
   end Equal;
        


end foo;

-------------------
--   FOO_2.ADS   --
-------------------


with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with Ada.Strings.Bounded;


package Foo_2 is
   type My_Map is tagged private;

   type Name_Class is (First, Second);

   type Descriptor (Class : Name_Class) is
      record
         case Class is
            when First =>
               null;

            when Second =>
               X : Float;
         end case;
      end record;

   procedure Zizi (X: My_Map);

private
   package Names is
     new Ada.Strings.Bounded.Generic_Bounded_Length (10);

   type Name_Type is new Names.Bounded_String;

   function To_String (X : Name_Type) return String
   is (Names.To_String (Names.Bounded_String (X)));

   function Hash (Key : Name_Type) return Ada.Containers.Hash_Type
   is (Ada.Strings.Hash (To_String (Key)));

   function Equal (Left, Right : Name_Type) return Boolean
   is (Left = Right);

   package Maps is
     new Ada.Containers.Indefinite_Hashed_Maps
       (Key_Type        => Name_Type,
        Element_Type    => Descriptor,
        Hash            => Hash,
        Equivalent_Keys => Equal);

   type My_Map is tagged
      record
         M : Maps.Map;
      end record;
end Foo_2;


-------------------
--   FOO_2.ADB   --
-------------------

package body Foo_2 is

   ----------
   -- Zizi --
   ----------

   procedure Zizi (X: My_Map) is
   begin
      null;
   end Zizi;

end Foo_2;


^ permalink raw reply	[relevance 6%]

* Re: Your wish list for Ada 202X
  2014-03-29  9:44  0%             ` Dmitry A. Kazakov
@ 2014-03-31 23:55  0%               ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2014-03-31 23:55 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:8bhozh836pyt$.1qctlysud0s2q$.dlg@40tude.net...
> On Fri, 28 Mar 2014 16:27:09 -0500, Randy Brukardt wrote:
>
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>> news:o4o5ao9k7hz9.l7ebk8qxfv32.dlg@40tude.net...
>>> On Thu, 27 Mar 2014 16:50:20 -0500, Randy Brukardt wrote:
>> ...
>>> Real issue: Multi-methods (String vs String) and full multiple dispatch
>>> (String vs Character)
>>
>> That's an alternative, but the question is whether that can be 
>> implemented
>> with less overhead than the scheme I suggested. I believe the answer is 
>> no,
>> at least within generalized string packages (which hopefully will become 
>> the
>> norm for new string operations in Ada).
>
> If and only if the generalized packages would define operations 
> class-wide.
> The idea is to rather make them primitive operations, so that a vendor (if
> he wanted to) could provide type-specific implementation for the cases of
> major interest, e.g.
>
>   overriding function "&" (L, R : String) return String;
>
> instead of inheriting (covariantly) ineffective parent's
>
>    function "&" (L, R : Root_String_Type) return Root_String_Type;

I don't understand how you are thinking the class-wide operations would work 
if everything isn't primitive. That's the only way for an Ada class-wide 
type to even be useful. So, of course each type will define useful primitive 
operations, and all of the root string operations will be primitive. 
(Indeed, the language definition already makes that so in the case of "&".)

> Root_String_Type would be an equivalent of Wide_Wide_String or UTF8_String
> or any other full Unicode character set string.

"Root_String_Type" would be abstract, and the other types would be derived 
from it. New types corresponding to each interesting representation would be 
defined. The existing types would still exist but be obsolescent.

...
>> Right, but that manifests itself in duplicated and overly restrictive
>> packages, which would have to be reworked in order to use a more general
>> interfaces. (Ada.Strings.Bounded and Ada.Strings.Unbounded in particular
>> have overloaded operations that would make everything ambiguous if not
>> eliminated.)
>
> If all string types are members of single class, then all corresponding
> overloaded operations are primitive operations on the class. Overloading 
> of
> overridden operations in guaranteed unambiguous. That is when you build a
> new hierarchy of string types.

Yes, of course, this is what I've proposing.

> Whether Unbounded_String should become a member of this new hierarchy or 
> be
> replaced there with a new type is another question.

It's not a question. There's no way to do that because the operations 
already defined for Unbounded_String would make it ambigious if given string 
literals (and all Root_String_Type'Class types would have string literals). 
It would be completely unusable.

As such, all new types is the only possibility. That's what makes this idea 
politically messy.

> Of course The former
> would be greatly preferable. This requires yet another feature Ada lacks -
> interface inheritance. Unbounded_String must drop parent's
> implementation/representation and inherit only the interface.

That's not the problem at all. (The parent here would have no 
representation, so there is nothing to drop.)

The problem is that Unbounded_String defines operations like

      function "&" (Left : Unbounded_String; Right : String) return 
Unbounded_String;

which would be ambiguous with the normal "&" if both String and 
Unbounded_String had string literals (as they must for Root_String_Type to 
work). Indeed, that's the only reason that Ada doesn't have a way to define 
string literals for a private type -- we talked about it years ago but 
determined that it cannot be used with any of the existing string packages. 
As such, it would have been a weird thing to define.

We can't get rid of these problematical operations -- it would be way too 
incompatible. So new packages is the only way to go.

                                  Randy.




^ permalink raw reply	[relevance 0%]

* Re: Your wish list for Ada 202X
  2014-03-28 21:27  5%           ` Randy Brukardt
@ 2014-03-29  9:44  0%             ` Dmitry A. Kazakov
  2014-03-31 23:55  0%               ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2014-03-29  9:44 UTC (permalink / raw)


On Fri, 28 Mar 2014 16:27:09 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:o4o5ao9k7hz9.l7ebk8qxfv32.dlg@40tude.net...
>> On Thu, 27 Mar 2014 16:50:20 -0500, Randy Brukardt wrote:
> ...
>> Real issue: Multi-methods (String vs String) and full multiple dispatch
>> (String vs Character)
> 
> That's an alternative, but the question is whether that can be implemented 
> with less overhead than the scheme I suggested. I believe the answer is no, 
> at least within generalized string packages (which hopefully will become the 
> norm for new string operations in Ada).

If and only if the generalized packages would define operations class-wide.
The idea is to rather make them primitive operations, so that a vendor (if
he wanted to) could provide type-specific implementation for the cases of
major interest, e.g.

   overriding function "&" (L, R : String) return String;

instead of inheriting (covariantly) ineffective parent's

    function "&" (L, R : Root_String_Type) return Root_String_Type;

Root_String_Type would be an equivalent of Wide_Wide_String or UTF8_String
or any other full Unicode character set string.

>> To reiterate the point. The implementation of strings in Ada is all OK, it
>> is the interface to this implementation which sucks.
> 
> Right, but that manifests itself in duplicated and overly restrictive 
> packages, which would have to be reworked in order to use a more general 
> interfaces. (Ada.Strings.Bounded and Ada.Strings.Unbounded in particular 
> have overloaded operations that would make everything ambiguous if not 
> eliminated.)

If all string types are members of single class, then all corresponding
overloaded operations are primitive operations on the class. Overloading of
overridden operations in guaranteed unambiguous. That is when you build a
new hierarchy of string types.

Whether Unbounded_String should become a member of this new hierarchy or be
replaced there with a new type is another question. Of course The former
would be greatly preferable. This requires yet another feature Ada lacks -
interface inheritance. Unbounded_String must drop parent's
implementation/representation and inherit only the interface.

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


^ permalink raw reply	[relevance 0%]

* Re: Your wish list for Ada 202X
  @ 2014-03-28 21:27  5%           ` Randy Brukardt
  2014-03-29  9:44  0%             ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2014-03-28 21:27 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:o4o5ao9k7hz9.l7ebk8qxfv32.dlg@40tude.net...
> On Thu, 27 Mar 2014 16:50:20 -0500, Randy Brukardt wrote:
...
> Real issue: Multi-methods (String vs String) and full multiple dispatch
> (String vs Character)

That's an alternative, but the question is whether that can be implemented 
with less overhead than the scheme I suggested. I believe the answer is no, 
at least within generalized string packages (which hopefully will become the 
norm for new string operations in Ada). It's surely one of the questions to 
be considered - nothing I think on this topic (or any topic, for that 
matter) is likely to be the last word.

> To reiterate the point. The implementation of strings in Ada is all OK, it
> is the interface to this implementation which sucks.

Right, but that manifests itself in duplicated and overly restrictive 
packages, which would have to be reworked in order to use a more general 
interfaces. (Ada.Strings.Bounded and Ada.Strings.Unbounded in particular 
have overloaded operations that would make everything ambiguous if not 
eliminated.)

                              Randy.




^ permalink raw reply	[relevance 5%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-06  3:03 11%     ` Brad Moore
@ 2013-12-06  4:43  6%       ` Rod Kay
  0 siblings, 0 replies; 200+ results
From: Rod Kay @ 2013-12-06  4:43 UTC (permalink / raw)


On Friday, 6 December 2013 14:03:09 UTC+11, Brad Moore  wrote:
> 
> Actually, this wasn't the only related change in Ada 2012. We also 
> allowed Remote_Types packages and Remote_Call_Interface packages to 
> depend on preelaborated packages, if that dependency is via a private 
> with clause.
> 

   Ah, that *is* nice. Will be quite useful, thank you. 

^ permalink raw reply	[relevance 6%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05 20:17 10%   ` Randy Brukardt
  2013-12-06  3:03 11%     ` Brad Moore
@ 2013-12-06  4:36  6%     ` Rod Kay
  1 sibling, 0 replies; 200+ results
From: Rod Kay @ 2013-12-06  4:36 UTC (permalink / raw)


On Friday, 6 December 2013 07:17:05 UTC+11, Randy Brukardt  wrote:
> We re-analyzed all of the existing packages for Ada 2005, and changed the 
> categorization of some of them. The details can be found in AI95-0362-1 
>

   Thank you for the detailed explanation, Randy. I see the matter has been given a good deal of thought. I'd be happy to submit a request for further consideration in the next standard, if it seems a reasonable request.

^ permalink raw reply	[relevance 6%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05  9:51  6% ` Georg Bauhaus
  2013-12-05 20:17 10%   ` Randy Brukardt
@ 2013-12-06  4:28  6%   ` Rod Kay
  1 sibling, 0 replies; 200+ results
From: Rod Kay @ 2013-12-06  4:28 UTC (permalink / raw)


On Thursday, 5 December 2013 20:51:40 UTC+11, Georg Bauhaus  wrote:
>
> Two possible reasons, guessing:
> 
> 1) pragma Pure being >= Ada 95, and compatibility,
> 
> 2) an implementation may choose to use pointers internally.

   Yes, both seem likely reasons, thanks.

^ permalink raw reply	[relevance 6%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05 20:17 10%   ` Randy Brukardt
@ 2013-12-06  3:03 11%     ` Brad Moore
  2013-12-06  4:43  6%       ` Rod Kay
  2013-12-06  4:36  6%     ` Rod Kay
  1 sibling, 1 reply; 200+ results
From: Brad Moore @ 2013-12-06  3:03 UTC (permalink / raw)


On 05/12/2013 1:17 PM, Randy Brukardt wrote:
> We re-analyzed all of the existing packages for Ada 2005, and changed the
> categorization of some of them. The details can be found in AI95-0362-1
> (http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00362.txt).
>
> There is a listing of every predefined package in that AI. Here's the entry
> for Bounded strings:
>
> Ada.Strings.Bounded -- A.4.4; Preelaborate
>    This package contains no state, no dependence on non-pure units, no
>    other items that prevent the package from being pure, and does not declare
>    any types that would be a problem for Annex E, so it could be declared
> pure.
>    But it's large and complex, and many of the operations are not
> conceptually
>    pure (they do in-place updates), so no change is recommended.
>
> This admittedly does not seem very satisfying. We didn't redo this exercise
> for Ada 2012, the only change we made was to make Stream_IO preelaborated so
> that loggers and the like can be written.

Actually, this wasn't the only related change in Ada 2012. We also 
allowed Remote_Types packages and Remote_Call_Interface packages to 
depend on preelaborated packages, if that dependency is via a private 
with clause.

See

http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05/ai05-0206-1.txt

This means that you can build abstractions that use Ada.Bounded_String 
(Or Ada.Tags for that matter), so long as they are not used in the 
visible part of a Remote_Types or Remote_Call_Interface package.

eg.

private with Ada.Strings.Bounded;

package RT is

    pragma Remote_Types;

    type W is private;

    procedure Set (Item : in out W;
                   Value : String);

    function Get (Item : W) return String;

private

    package My_String is new
      Ada.Strings.Bounded.Generic_Bounded_Length (Max => 100);

    type W is
       record
          D : My_String.Bounded_String;
       end record;

    function Get (Item : W) return String is (My_String.To_String (Item.D));
end RT;

package body RT is

    procedure Set
      (Item : in out W;
       Value : String) is
    begin
       My_String.Set_Bounded_String (Target => Item.D,
                                     Source => Value);
    end Set;

end RT;

Brad.

  (It's not practical to make the
> full Text_IO preelaborated [the obvious approach is not task-safe], and
> there was no agreement on the contents of a preelaborable subset.) I suppose
> you could send a request to reconsider this to Ada-Comment (but it would
> probably have to wait until the next Standard, whenever that is).
>
> Someone asked about Ada.Tags. The entry for it says:
>
> Ada.Tags -- 3.9; not categorized
>    Package Tags has state, so it cannot be pure. That state is generally
> either
>    set up at link-time (before elaboration) or during the elaboration of
> tagged
>    types (that is, during the elaboration of other units). In either case, no
>    complex state need be initialized at elaboration time. Thus, this package
>    can be Preelaborated.
>
> (The "state" that is talked about here is the table of internal tag <=>
> external tag mappings. Distributing that could be a significant overhead.)
> Making it Pure is not practical.
>
>                                   Randy.
>
> "Georg Bauhaus" <rm.dash-bauhaus@futureapps.de> wrote in message
> news:52a04caa$0$6636$9b4e6d93@newsspool2.arcor-online.net...
>> On 05.12.13 04:58, Rod Kay wrote:
>>> Hi all,
>>>
>>>      Would anyone know the reason for this ?
>>
>> Two possible reasons, guessing:
>>
>> 1) pragma Pure being >= Ada 95, and compatibility,
>>
>> 2) an implementation may choose to use pointers internally.
>>
>
>

^ permalink raw reply	[relevance 11%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05  9:51  6% ` Georg Bauhaus
@ 2013-12-05 20:17 10%   ` Randy Brukardt
  2013-12-06  3:03 11%     ` Brad Moore
  2013-12-06  4:36  6%     ` Rod Kay
  2013-12-06  4:28  6%   ` Rod Kay
  1 sibling, 2 replies; 200+ results
From: Randy Brukardt @ 2013-12-05 20:17 UTC (permalink / raw)


We re-analyzed all of the existing packages for Ada 2005, and changed the 
categorization of some of them. The details can be found in AI95-0362-1 
(http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00362.txt).

There is a listing of every predefined package in that AI. Here's the entry 
for Bounded strings:

Ada.Strings.Bounded -- A.4.4; Preelaborate
  This package contains no state, no dependence on non-pure units, no
  other items that prevent the package from being pure, and does not declare
  any types that would be a problem for Annex E, so it could be declared 
pure.
  But it's large and complex, and many of the operations are not 
conceptually
  pure (they do in-place updates), so no change is recommended.

This admittedly does not seem very satisfying. We didn't redo this exercise 
for Ada 2012, the only change we made was to make Stream_IO preelaborated so 
that loggers and the like can be written. (It's not practical to make the 
full Text_IO preelaborated [the obvious approach is not task-safe], and 
there was no agreement on the contents of a preelaborable subset.) I suppose 
you could send a request to reconsider this to Ada-Comment (but it would 
probably have to wait until the next Standard, whenever that is).

Someone asked about Ada.Tags. The entry for it says:

Ada.Tags -- 3.9; not categorized
  Package Tags has state, so it cannot be pure. That state is generally 
either
  set up at link-time (before elaboration) or during the elaboration of 
tagged
  types (that is, during the elaboration of other units). In either case, no
  complex state need be initialized at elaboration time. Thus, this package
  can be Preelaborated.

(The "state" that is talked about here is the table of internal tag <=> 
external tag mappings. Distributing that could be a significant overhead.) 
Making it Pure is not practical.

                                 Randy.

"Georg Bauhaus" <rm.dash-bauhaus@futureapps.de> wrote in message 
news:52a04caa$0$6636$9b4e6d93@newsspool2.arcor-online.net...
> On 05.12.13 04:58, Rod Kay wrote:
>> Hi all,
>>
>>     Would anyone know the reason for this ?
>
> Two possible reasons, guessing:
>
> 1) pragma Pure being >= Ada 95, and compatibility,
>
> 2) an implementation may choose to use pointers internally.
> 


^ permalink raw reply	[relevance 10%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05  3:58  6% Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ? Rod Kay
  2013-12-05  6:50  6% ` Shark8
@ 2013-12-05  9:51  6% ` Georg Bauhaus
  2013-12-05 20:17 10%   ` Randy Brukardt
  2013-12-06  4:28  6%   ` Rod Kay
  1 sibling, 2 replies; 200+ results
From: Georg Bauhaus @ 2013-12-05  9:51 UTC (permalink / raw)


On 05.12.13 04:58, Rod Kay wrote:
> Hi all,
>
>     Would anyone know the reason for this ?

Two possible reasons, guessing:

1) pragma Pure being >= Ada 95, and compatibility,

2) an implementation may choose to use pointers internally.



^ permalink raw reply	[relevance 6%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05  6:50  6% ` Shark8
@ 2013-12-05  8:16  6%   ` Rod Kay
  0 siblings, 0 replies; 200+ results
From: Rod Kay @ 2013-12-05  8:16 UTC (permalink / raw)


On Thursday, 5 December 2013 17:50:57 UTC+11, Shark8  wrote:
> 
> Does DSA = Distributed System Application?

Yes .. or Distributed Systems Annex ... much the same thing.

^ permalink raw reply	[relevance 6%]

* Re: Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
  2013-12-05  3:58  6% Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ? Rod Kay
@ 2013-12-05  6:50  6% ` Shark8
  2013-12-05  8:16  6%   ` Rod Kay
  2013-12-05  9:51  6% ` Georg Bauhaus
  1 sibling, 1 reply; 200+ results
From: Shark8 @ 2013-12-05  6:50 UTC (permalink / raw)


On Wednesday, December 4, 2013 8:58:46 PM UTC-7, Rod Kay wrote:
> Hi all,
> 
> 
> 
>    Would anyone know the reason for this ? 
> 
> 
> 
>    Bounded strings would appear to be useful for DSA at least. As a test, I copied/renamed the relevant bounded string packages and made them Pure and found no obvious problems (a simple test compiled and ran ok).

Does DSA = Distributed System Application?
Another package that would be nice in a different categorization is Ada.Tags (it would be nice to be able to use them across DSA partitions and in remote-call interfaces).



^ permalink raw reply	[relevance 6%]

* Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ?
@ 2013-12-05  3:58  6% Rod Kay
  2013-12-05  6:50  6% ` Shark8
  2013-12-05  9:51  6% ` Georg Bauhaus
  0 siblings, 2 replies; 200+ results
From: Rod Kay @ 2013-12-05  3:58 UTC (permalink / raw)


Hi all,

   Would anyone know the reason for this ? 

   Bounded strings would appear to be useful for DSA at least. As a test, I copied/renamed the relevant bounded string packages and made them Pure and found no obvious problems (a simple test compiled and ran ok).


regards,
Rod.


^ permalink raw reply	[relevance 6%]

* Re: Optimizing Ada
  @ 2013-10-02 18:58  5%       ` John B. Matthews
  0 siblings, 0 replies; 200+ results
From: John B. Matthews @ 2013-10-02 18:58 UTC (permalink / raw)


In article <l2g6i7$8mm$1@dont-email.me>,
 Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> wrote:

> On 10/01/2013 08:53 PM, kennethesills@gmail.com wrote:
> >> Ada is the fastest correct implementation you have.
> >
> > Yes. However, is case sensitivity the reason for a 2.7x slow down? 
> > Highly unlikely. In fact, using case-sensitive comparisons in Ada 
> > only reduce the time taken by around 50ns. So I just disregarded 
> > that fact.
> 
> I agree that the implementation of Indefinite_Hashed_Maps is probably 
> the culprit, but until you have an apples-to-apples comparison, you 
> have no complaint. (Actually, I can't think of any application that 
> could use such a function where the difference would prevent it from 
> meeting reasonable timing requirements, so you probably have no 
> complaint anyway.)

kennethesills: For comparison with Indefinite_Hashed_Maps, this example 
uses an instance of Ada.Strings.Bounded.Generic_Bounded_Length as the 
Key_Type in an instance of Ada.Containers.Hashed_Maps. Your problem 
domain may suggest a suitable maximum length.

<http://home.roadrunner.com/~jbmatthews/jumble.html>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>


^ permalink raw reply	[relevance 5%]

* Re: Hash Type Size
  2013-09-03 17:18  0%             ` Peter Brooks
@ 2013-09-03 21:21  0%               ` John B. Matthews
  0 siblings, 0 replies; 200+ results
From: John B. Matthews @ 2013-09-03 21:21 UTC (permalink / raw)


In article <c6c24f9a-c5ba-4068-be58-c7d1cff4889b@googlegroups.com>,
 Peter Brooks <peter.h.m.brooks@gmail.com> wrote:

> On Tuesday, 3 September 2013 12:50:04 UTC+2, John B. Matthews  wrote:
> > 
> > As a concrete example, this program [1] tallies collisions 
> > using an  instance of Ada.Strings.Bounded.Hash on words found 
> > in a dictionary.  While it's specific to GNAT, it may suggest 
> > how to obtain a baseline against which to compare your 
> > implementation(s).
> > 
> > [1] <http://home.roadrunner.com/~jbmatthews/jumble.html#sec2>
> > 
> Thank you for that -it's extremely useful. 32% collisions is far 
> too high for me, so I certainly need a better hash function.

You are welcome. That 2009 data was obtained using GNAT 4.3.4; 
newer versions are typically better. For example, the GNAT 4.6 
implementation yields the following result:

./collisions
 0: 305643 (77.72%)
 1: 76947 (19.57%)
 2: 9790 (2.49%)
 3: 805 (0.20%)
 4: 56 (0.01%)
 5: 1 (0.00%)

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

^ permalink raw reply	[relevance 0%]

* Re: Hash Type Size
  2013-09-03 10:50  5%           ` John B. Matthews
@ 2013-09-03 17:18  0%             ` Peter Brooks
  2013-09-03 21:21  0%               ` John B. Matthews
  0 siblings, 1 reply; 200+ results
From: Peter Brooks @ 2013-09-03 17:18 UTC (permalink / raw)


On Tuesday, 3 September 2013 12:50:04 UTC+2, John B. Matthews  wrote:
> 
> As a concrete example, this program [1] tallies collisions using an  
> instance of Ada.Strings.Bounded.Hash on words found in a dictionary.  
> While it's specific to GNAT, it may suggest how to obtain a baseline 
> against which to compare your implementation(s).
> 
> [1] <http://home.roadrunner.com/~jbmatthews/jumble.html#sec2>
> 
Thank you for that -it's extremely useful. 32% collisions is far too high for me, so I certainly need a better hash function.


^ permalink raw reply	[relevance 0%]

* Re: Hash Type Size
  @ 2013-09-03 10:50  5%           ` John B. Matthews
  2013-09-03 17:18  0%             ` Peter Brooks
  0 siblings, 1 reply; 200+ results
From: John B. Matthews @ 2013-09-03 10:50 UTC (permalink / raw)


In article <8268e85c-e372-4883-8449-ef5253e2c77e@googlegroups.com>,
 Peter Brooks <peter.h.m.brooks@gmail.com> wrote:

> The triples are of the form:
> 
> <http://dbpedia.org/resource/Alabama> 
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
> <http://schema.org/AdministrativeArea>
> 
> subject - predicate - object
> 
> Clearly the '<http://' and '>' don't need to be part of the hash, 
> I'll need a mapping both ways, from subject -> predicate -> 
> object and from object -> predicate -> subject, that's what'll be 
> in the binary trees.

As a concrete example, this program [1] tallies collisions using an 
instance of Ada.Strings.Bounded.Hash on words found in a dictionary. 
While it's specific to GNAT, it may suggest how to obtain a baseline 
against which to compare your implementation(s).

[1] <http://home.roadrunner.com/~jbmatthews/jumble.html#sec2>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>


^ permalink raw reply	[relevance 5%]

* Re: 4 beginner's questions on the PL Ada
  @ 2013-08-10  6:16  6%               ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2013-08-10  6:16 UTC (permalink / raw)


Emanuel Berg <embe8573@student.uu.se> writes:

> Anh Vo <anhvofrcaus@gmail.com> writes:
>
>> You can give/assign a name to a task the way you like by using
>> predefined package Ada.Task_Attributes. In this case you most
>> likely instantiate it with String subtype. Therefore, it is will
>> be completely portable.
>
> And (drumroll...) how would that look?

Well, it turns out to be more complicated than Ahn Vo said, because
Ada.Task_Attributes[1] has to be instantiated with a definite type (it
begins "type Attribute is private;") and String is indefinite.

So it might look like

with Ada.Strings.Bounded;
with Ada.Task_Attributes;
with Ada.Task_Identification;
with Ada.Text_IO; use Ada.Text_IO;
procedure Task_Naming is
   package Task_Name_Strings
   is new Ada.Strings.Bounded.Generic_Bounded_Length (Max => 64);
   package Task_Names
   is new Ada.Task_Attributes
     (Attribute => Task_Name_Strings.Bounded_String,
      Initial_Value => Task_Name_Strings.Null_Bounded_String);
   task Tsk is end Tsk;
   task body Tsk is
   begin
      delay 5.0;
   end Tsk;
begin
   Task_Names.Set_Value (T => Tsk'Identity,
                         Val => Task_Name_Strings.To_Bounded_String ("foo"));
   --  later ...
   Put_Line
     ("id is "
        & Task_Name_Strings.To_String (Task_Names.Value (Tsk'Identity)));
end Task_Naming;

Alternatively, you could say

   subtype Task_Name_String is String (1 .. 16);
   package Task_Names
   is new Ada.Task_Attributes
     (Attribute => Task_Name_String,
      Initial_Value => (others => ' '));

but then you'd have to say

   Task_Names.Set_Value (T => Tsk'Identity,
                         Val => ('f', 'o', 'o', others => ' '));

> You guys should do a field trip to gnu.emacs.help - there, we just
> post code all days! It is much better. Code speaks louder than
> words. It is very difficult to follow all this discussion on
> memory allocation etc., but the few times you posted code there
> wasn't a letter I didn't understand immediately.

We don't like to post code that doesn't work, and producing a working
example takes time. Also, we have an excellent on-line reference manual,
though it takes a special kind of person to want to read it at bed-time!

[1] http://www.adaic.org/resources/add_content/standards/12rm/html/RM-C-7-2.html


^ permalink raw reply	[relevance 6%]

* Re: Ada and string literals
  @ 2013-01-30 13:52  5%     ` Niklas Holsti
  0 siblings, 0 replies; 200+ results
From: Niklas Holsti @ 2013-01-30 13:52 UTC (permalink / raw)


On 13-01-30 13:50 , Mart van de Wege wrote:
> Niklas Holsti <niklas.holsti@tidorum.invalid> writes:
> 
>> On 13-01-30 02:44 , codeallergy wrote:
>>> hi comp.lang.ada, 
>>>
>>> question from a newcomer: Why ada does not allow using a string
>>> literal with access type ?
>>>
>>> abc : access string := "LITERAL"; -- error.
>>
>> Because, unlike C, Ada does not confuse arrays with pointers.
>>
>> This is the closest Ada equivalent:
>>
>>    Literal : aliased constant String := "LITERAL";
>>    abc     : access constant String := Literal'Access;
> 
> More importantly, I cannot see why you would want an access to a string
> literal.
> 
> Just use the string literal as a normal parameter, and let the compiler
> worry about how to handle that.

I don't know why the OP wants an access, but I can image a situation
where one needs, for example, to call a subprogram with several string
parameters, which should have different values depending on different
logical conditions, in various combinations. It is then easier to
represent each parameter by local variable that can be assigned
different values in different if-then-else statements, and then use the
local variables as actual parameters in the call.

For example, assume you must call a procedure Foo (A, B: in String), and
A can be either "James" or "John" depending on condition Alpha, while B
can be either "Jill" or "Jennie" depending on condition Beta. You would
like to write something like this:

   -- The following does NOT work:
   ..
   is
      A, B : String;
   begin
      if Alpha then A := "James"; else A := "John"  ; end if;
      if Beta  then B := "Jill";  else B := "Jennie"; end if;
      Foo (A, B);
   ..

That doesn't work, because the declaration of A and B must specify a
length for the string, and then you cannot assign literal strings of
different length to A and B.

If you use string literals directly as parameters, you need different
calls for all combinations:

   if Alpha then
      if Beta then
         Foo ("James", "Jill");
      else
         Foo ("James", "Jennie");

and so on, for a combinatorial number of cases.

Of course you can use Ada.Strings.Unbounded or Ada.Strings.Bounded,
which let you assign strings of different lengths to the same variable,
but accesses to strings are another solution.

In the above simple example one could also use Ada 2012 conditional
expressions:

   Foo (A => (if Alpha then "James" else "John"  ),
        B => (if Beta  then "Jill"  else "Jennie"));

but in more complex cases that no longer works, or not as well as
assigning the actual parameter values to local variables before the call.

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



^ permalink raw reply	[relevance 5%]

* Re: problems with interfacing c
  @ 2011-01-28  9:41  5%     ` Ludovic Brenta
  0 siblings, 0 replies; 200+ results
From: Ludovic Brenta @ 2011-01-28  9:41 UTC (permalink / raw)


Staszek Goldstein wrote on comp.lang.ada:
> I am sending a solution to a problem to a site managing programming contests, and
> the stdin is in fact redirected to some text file with data. I do not know how
> big the data file will be, I know only the upper limit. Quick reading of the data is the
> key to success, and the two lines of C work very well for the purpose. I have not
> tried your solution, is it not going to cause constraint_error when it meets the end of the
> file?

If you really read from Standard_Input, there is no upper limit to the
size of the file, so you should not depend on one. i.e. your program
should work if you say:

$ yes | my_program

The proper way to read a potentially infinite amount of data from
Standard_Input is to read one character at a time, buffer the input
for processing, and discard the buffer from time to time so your
program runs in constant memory. The points in time where you discard
the buffer depend on the algorithm.

Like Dmitry, I strongly suggest you use Ada.Streams, not Ada.Text_IO,
because the latter is much slower (it does a lot of unnecessary
bookkeeping behind the scenes).

Here is a small example where I process the input buffer whenever it
is full and then discard it. I also do that when I reach the end of
the input stream. Note that I have not compiled this example, so it
may contain (intentional :)) bugs.

with Ada.IO_Exceptions;
with Ada.Text_IO;
with Ada.Strings.Bounded;
procedure My_Program is
   Current_Input : constant Ada.Text_IO.Text_Streams.Stream_Access :=
     Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Current_Input);
   package Buffers is new Ada.Strings.Bounded.Generic_Bounded_Length
(Max => 100_000);

   procedure Process_And_Discard (Buffer : in out
Buffers.Bounded_String) is
   begin
      -- actual processing left as an exercise for the reader :)
      Buffers.Delete (Source => Buffer, From => 1, Through =>
Buffers.Max_Length);
   end Process_And_Discard;

   Buffer : Buffers.Bounded_String;
begin
   loop
      declare
          C : Character;
      begin
          Character'Read (Current_Input, C);
          if Buffers.Length (Buffer) = Buffers.Max_Length then --
buffer is full
             Process_And_Discard (Buffer);
          end if;
          Buffers.Append (Source => Buffer, New_Item => C);
      exception
          when Ada.IO_Exceptions.End_Error => -- end of stream reached
             Process_And_Discard (Buffer); -- process whatever we read
last
             exit;
      end;
   end loop;
end My_Program;

> The other question is - how to use the C bindings properly in such a case?

Don't.

--
Ludovic Brenta.



^ permalink raw reply	[relevance 5%]

* Re: confusion with string initialization
  @ 2010-04-19 18:20  7%       ` John B. Matthews
  0 siblings, 0 replies; 200+ results
From: John B. Matthews @ 2010-04-19 18:20 UTC (permalink / raw)


In article <hqhod3$tit$1@news.eternal-september.org>,
 "J-P. Rosen" <rosen@adalog.fr> wrote:

> Colin Paul Gloster a écrit :
> 
> > Why did you consider a book which makes which packages things are 
> > in unclear by mutiliating programs by means of the USE keyword to 
> > be excellent?
> 
> Because it makes lisibility a lot better by drawing attention of the 
> reader on what actually the thing does, and getting rid of useless 
> information that you can find easily by clicking on the identifier 
> and selecting "go to declaration".
> 
> (Ok, Ok, I'm a bit provocative here, but I'm tired of seeing people 
> jumping on beginners and insisting on a notation that can drive them 
> away of the language screaming).

Preferring not to overuse "use", I recall becoming an instant fan of 
"use type" when it was introduced in Ada '95. Is there a way to make 
Ada.Strings.Fixed."*" visible without the use clause?

with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Bounded;
with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure UseType is
   package String20 is new
      Ada.Strings.Bounded.Generic_Bounded_Length(20);
   use type String20.Bounded_String;

   package StringN renames Ada.Strings.Unbounded;
   use type StringN.Unbounded_String;

   SB : constant String20.Bounded_String := 20 * '*';
   SN : constant StringN.Unbounded_String := 20 * '*';
   S1 : constant String := Ada.Strings.Fixed."*"(20, '*');
   S2 : constant String := 20 * '*';
begin
   Ada.Text_IO.Put_Line(String20.To_String(SB));
   Ada.Text_IO.Put_Line(StringN.To_String(SN));
   Ada.Text_IO.Put_Line(S1);
   Ada.Text_IO.Put_Line(S2);
end UseType;

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>



^ permalink raw reply	[relevance 7%]

* Re: confusion with string initialization
    2010-04-17 17:42  7% ` 
@ 2010-04-18  2:13  7% ` brett
    1 sibling, 1 reply; 200+ results
From: brett @ 2010-04-18  2:13 UTC (permalink / raw)


Thank you all for your very useful information, Thomas Locke's full example
of Barnes code was extremely helpful. Which I dropped into GNAT for testing.

I was having problems resolving the what? packages I needed to be able to process bounded strings, I'd already sucessfully written a Unbounded strings program and could not see why Bounded strings were causing me so many problems !
The need for "Generic_Bounded_Length" part was very unclear, and hoe it related to the rest of my code.

BTW: John Barnes Ada 2005 Book is truly excellent, however I think I also need a more "Practical Ada 2005 Programming" book as well. The titles I see on Internet book sellers are mainly Ada95 and I'm unsure if they have any relevance to learning Ada 2005. Any Suggestions ??



My finished test program is :

-- brett hallett : 18/10/2010
-- testing --redefined Integer type Temp_Int
           --Bounded String type 
with Ada.Strings.Bounded; use Ada.Strings.Bounded;
with Ada.Text_IO.Bounded_IO;

procedure calctemp4 is
 use Ada.Strings.Bounded;
 use Ada.Text_IO;
 
subtype Temp_Int is integer range 50 .. 350 ;

 package BS is new Generic_Bounded_Length(30);  use BS;
--	define the 'base' string to work with
 package BS_IO is new Bounded_IO ( BS );        use BS_IO;

strline : BS.Bounded_String := (BS.Max_Length * " ");
-- create & initialize strline to spaces

C : Temp_Int := Temp_Int'First;    -- start temperature
F : Integer;

function convert ( X : Integer ) return Integer is
  F : Integer;
begin
    F := (( X * 9 )/ 5  ) +32; -- standard C to F calc
    return F;
end convert;

begin

   put_line("calctemp");
   put(" Celsius   Farhenheit"); new_line;
   
   while C < Temp_Int'Last loop -- loop in range

        BS.overwrite(strline, 1,  c'img);
        f := convert(c);
        BS.overwrite(strLine, 10, f'img);
   	BS_IO.Put_line(strline);
        C := C + 25;
        strline := BS.Max_Length * "*";
        -- 'clear' strline ( not necessary , just testing :-)
   end loop;
   put("  -- finished--"); new_line;
end calctemp4;




---
frmsrcurl: http://compgroups.net/comp.lang.ada/confusion-with-string-initialization



^ permalink raw reply	[relevance 7%]

* Re: confusion with string initialization
  @ 2010-04-17 17:42  7% ` 
  2010-04-18  2:13  7% ` brett
  1 sibling, 0 replies; 200+ results
From:  @ 2010-04-17 17:42 UTC (permalink / raw)


brett wrote:
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 
> 
> bs := 20 * " ";  
> 
> construct, which always gives an error 
> 
> "universal integer expected"
> 
> As my syntax is similar to that in Ada 2005 book by Barnes
> (page 594 & 596) I'm a bit confused :-)
> Searching the ARM was of no value either !
> 
> Thanks for any input

Hey Brett,

Here's how the complete example from the excellent John Barnes book 
could look:


with Ada.Strings.Bounded;           use Ada.Strings.Bounded;
with Ada.Strings.Fixed;             use Ada.Strings.Fixed;
with Ada.Strings.Unbounded;         use Ada.Strings.Unbounded;
with Ada.Text_IO;                   use Ada.Text_IO;
with Ada.Text_IO.Bounded_IO;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;

procedure String_Test is
    package Bounded_80 is new Generic_Bounded_Length (80);
    use Bounded_80;
    package Bounded_80_IO is new Bounded_IO (Bounded_80);
    use Bounded_80_IO;

    BS : Bounded_String;
    US : Unbounded_String;
    S15 : String (1 .. 15);
begin
    BS := 2 * "Bar";
    Put_Line (BS);

    US := 3 * 'A';
    Put_Line (US);

    US := 2 * US;
    Put_Line (US);

    S15 := 5 * "SOS";
    Put_Line (S15);
end String_Test;


And here's the output you should get when executing the program:

BarBar
AAA
AAAAAA
SOSSOSSOSSOSSOS

-- 
Regards,
Thomas L�cke

Email: tl at ada-dk.org
Web: http:ada-dk.org
IRC nick: ThomasLocke



^ permalink raw reply	[relevance 7%]

* Table of pointers question
@ 2009-09-24  0:47  5% Rob Solomon
  0 siblings, 0 replies; 200+ results
From: Rob Solomon @ 2009-09-24  0:47 UTC (permalink / raw)


I am working my way thru Ada As A Second Language by Norman Cohen (c)
1996

This confuses me.

It is a simple sorting routine that swaps pointers rather than the
data.  Note that the variables are more like Modula-2 syntax as I am
very comfortable with that.  And it is easier to type.

with Ada.Text_IO, Ada.Strings.Bounded; use Ada.Text_IO;
procedure PrintDirectory is
  maxLineLength : constant := 80;
  maxEntries    : constant := 1000;
  
  package InputLines is new Ada.Strings.Bounded.Generic_Bounded_Length
(MaxLineLength);
  
  use InputLines;
  
  type DirectoryEntryType is
    record
      NamePart, StreetPart, CityPart: Bounded_String;
    end record;
  
  type DirectoryEntryPointerType is access DirectoryEntryType;
  
  NewEntry        : DirectoryEntryPointerType;
  Buffer          : String (1..MaxLineLength);
  Length          : Integer range 0..MaxLineLength;
  OutOfPlaceEntry : DirectoryEntryPointerType;
  NumberOfEntries : Integer range 0..MaxEntries := 0;
  No_Exchanges    : Boolean;
  
  EntryList        : array (1..MaxEntries) of DirectoryEntryType;
  EntryPointerList : array (1..MaxEntries) of
DirectoryEntryPointerType;
  
begin
  -- read data into entry list
  WHILE NOT End_Of_File LOOP
    Get_Line(Buffer, length);
    NewEntry.NamePart := To_Bounded_String(Buffer(1..Length));
    Get_Line(Buffer, Length);
    NewEntry.StreetPart := To_Bounded_String(Buffer(1..Length));
    Get_Line(Buffer, Length);
    NewEntry.CityPart := To_Bounded_String(Buffer(1..Length));
    NumberOfEntries := NumberOfEntries + 1;
    EntryPointerList(NumberOfEntries) := new
DirectoryEntryType'(NewEntry);  -- MY QUESTION HERE
  END LOOP;
  
  -- sort entryList using bubble sort
  
  LOOP
    No_Exchanges := True;
    FOR I in 1 .. NumberOfEntries - 1 LOOP
      IF EntryPointerList(I).NamePart > EntryPointerList(I+1).NamePart
THEN
        OutOfPlaceEntry := EntryPointerList(I+1);
        EntryPointerList(I+1) := EntryPointerList(I);
        EntryPointerList(I) := OutOfPlaceEntry;
        No_Exchanges := False;
      END IF:
    END LOOP;
    EXIT WHEN No_Exchanges;
  END LOOP;
  
  -- write sorted data
  FOR I in 1 .. NumberOfEntries LOOP
    Put_Line(To_String(EntryPointerList(I).NamePart));
    Put_Line(To_String(EntryPointerList(I).StreetPart));
    Put_Line(To_String(EntryPointerList(I).CityPart));
  END LOOP;


My question is that I would expect to have an array that contains the
data, and a second array that is an array of pointers to the 1st
array.  The example does not define that.

How does the line:
EntryPointerList(NumberOfEntries) := new DirectoryEntryType'(NewEntry)
;

Do what's needed?

Thanks



^ permalink raw reply	[relevance 5%]

* Re: Array of Strings
  @ 2008-09-13 14:32  6% ` Ludovic Brenta
  0 siblings, 0 replies; 200+ results
From: Ludovic Brenta @ 2008-09-13 14:32 UTC (permalink / raw)


jedivaughn <jedivaughn14@gmail.com> writes:
> Hi everyone,
>
> I'm having trouble making a array of type string. can some one show me
> how to do this. I've tried type letters is array (Integer range <>) of
> String; but I get error "unconstrained element type in array
> declaration". what am I doing wrong?

The type String is unconstrained because you don't know the size of
the strings at compile time.  Therefore you cannot put Strings in an
array.  You can however create:

- an array of fixed-size strings; for this you need a subtype e.g.

subtype Constrained_String is String (1 .. 10);
type Array_Of_Constrained_Strings is
  array (Positive range <>) of Constrained_String;

- an array of access values to Strings e.g.

type String_Access is access String;
type Array_Of_String_Accesses is array (Positive range <>) of String_Access;

(!this is the most error-prone method!)

- an array of Ada.Strings.Unbounded.Unbounded_Strings e.g.

type Array_Of_Unbouded_Strings is
  array (Positive range <>) of Ada.Strings.Unbounded.Unbounded_String;

- an array of Ada.Strings.Bounded.Bounded_Strings similar to the above
  but you also need to specify the maximum size

HTH

-- 
Ludovic Brenta.



^ permalink raw reply	[relevance 6%]

* Re: Limited returns
  @ 2008-06-24 10:56  5%       ` fedya_fedyakoff
  0 siblings, 0 replies; 200+ results
From: fedya_fedyakoff @ 2008-06-24 10:56 UTC (permalink / raw)


> Even if it could, that would not make the program illegal. The compiler
> could only warn you about a possible exception propagation, which is not an
> error.

Well, I thought the compiler must warn about possible exception,
especially when there is such a possibility.

Ok, this is just my opinion, but returning to our rams - some
strangeness (an error?) is still there - consider:

--- named.ads
package Named is
   type Object is interface;

   function  name(this: Object) return String is abstract;
end Named;

--- some.ads
with Named;
with Ada.Finalization; use Ada.Finalization;
with Ada.Strings.Bounded;

package Some is
   Size : constant := 80;
   package bs is new Ada.Strings.Bounded.Generic_Bounded_Length(Size);
   use bs;

   type Object is new Controlled and Named.Object with private;

   function Create( name: String ) return Object;

   overriding procedure Initialize(this: in out Object);
   overriding procedure Finalize(this: in out Object);
   overriding procedure Adjust(this: in out Object);

   overriding function  name(this: Object) return String;

private
   type Object is new Controlled and Named.Object with
      record
         the_name: Bounded_String;
      end record;
end Some;

--- some.adb
with ada.Text_IO;
with system;

package body Some is
   package tio renames ada.Text_IO;

   function Create( name: String ) return Object is
   begin
      return O : Object do
         O.the_name := To_Bounded_String(name);
      end return;
   end Create;


   procedure Initialize(this: in out Object) is
   begin
      tio.Put_Line("Initialization " & this.name );
   end Initialize;

   procedure Finalize(this: in out Object) is
   begin
      tio.Put_Line("Finalization " & this.name);
   end Finalize;

   procedure Adjust(this: in out Object) is
   begin
      tio.Put_Line("Ajusting " & this.name);
   end Adjust;

   function name(this: Object) return String is
   begin
      return To_String(this.the_name);
   end name;

end Some;

--- factory.ads
with Named;

package Factory is
   function Create(name: String) return Named.Object'Class;
end Factory;

--- factory.adb
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Some;

package body Factory is

   function Create(name: String) return Named.Object'Class is
   begin
   	return Some.Create(name);
   end;
end Factory;

--- boom.adb
with ada.Text_IO;
with Named; use Named;
with Factory;


procedure boom is
   package tio renames ada.Text_IO;
   aNamed: Named.Object'Class := Factory.create("Some1");
begin
   aNamed := Factory.create("Some1"); --- ***
   tio.put_line( "My name is " & aNamed.name );
   tio.Flush;
end boom;


What I can't figure out is why it's crashed at *** ? Factory creates
two fully equivalent objects of the same type!
Program's output looks very strange as well (at least for me) - why
for two initialization we have five (!!!) finalization? It drives me
crazy!

The program output is as follows:

Initialization
Ajusting Some1
Finalization Some1
Ajusting Some1
Initialization
Ajusting Some1
Finalization Some1
Finalization Some1
Finalization Some1
Finalization Some1

Execution terminated by unhandled exception
Exception name: CONSTRAINT_ERROR
Message: boom.adb:10 tag check failed
Call stack traceback locations:
0x401b69 0x401676 0x401235 0x401286 0x7c816d4d
[2008-06-24 14:51:09] process exited with status1 (elapsed time:
00.14s)





^ permalink raw reply	[relevance 5%]

* another way to shoot yourself in the foot?
@ 2008-06-20  9:03  5% fedya_fedyakoff
  0 siblings, 0 replies; 200+ results
From: fedya_fedyakoff @ 2008-06-20  9:03 UTC (permalink / raw)


Consider a very simple code. Suppose we have

1) a Named interface as this

--- named.ads ---

package Named is
   type Object is limited interface;

   function  name(this: Object) return String is abstract;
end Named;

2) Simple implementation

--- Some.ads ---

with Named;
with Ada.Finalization; use Ada.Finalization;
with Ada.Strings.Bounded;

package Some is

   Size : constant := 80;

   package bs is new Ada.Strings.Bounded.Generic_Bounded_Length(Size);
   use bs;

   type Object is new Limited_Controlled and Named.Object with
private;


   function Create( name: String ) return Object;

   overriding procedure Initialize(this: in out Object);
   overriding procedure Finalize(this: in out Object);

   overriding function  name(this: Object) return String;


private
   type Object is new Limited_Controlled and Named.Object with
      record
         the_name: Bounded_String;
      end record;
end Some;

--- Some.adb ---

with ada.Text_IO;

package body Some is
   package tio renames ada.Text_IO;

   function Create( name: String ) return Object is
   begin
      return O : Object do
         O.the_name := To_Bounded_String(name);
      end return;
   end Create;


   procedure Initialize(this: in out Object) is
   begin
      tio.Put_Line("Initialization Car " & this.name);
   end Initialize;

   procedure Finalize(this: in out Object) is
   begin
      tio.Put_Line("Finalization Car " & this.name);
   end Finalize;


   function name(this: Object) return String is
   begin
      return To_String(this.the_name);
   end name;

end Some;

3) Simple factory function as follows:

--- Factory ads ---
with Named;
with Some;

package Factory is
   function Create(class: String; name: String) return
Named.Object'Class;
end Factory;

--- Factory.adb ---

with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Some;

package body Factory is
   --- this one is ugly, but in sake of simplicity ...
   function Create(class: String; name: String) return
Named.Object'Class is
   begin
      if Index(class, "Some") /= 0 then
         return Some.Create(name);
      end if;
      raise Program_Error with "Unknown class " & class;
   end;
end Factory;
---------------

4) And finally main procedure

--- boom.adb ---

with ada.Text_IO;
with Named; use Named;
with Factory;
with Some;

procedure boom is
   package tio renames ada.Text_IO;
   aNamed: Some.Object := Some.Create("One");
begin
     declare
        aNamed1: Named.Object'Class := Factory.Create("Some", "Two");
     begin
        tio.put_line( "car: " & aNamed1.name ); ---booooooommm!!!
     end;

   tio.put_line( "car: " & aNamed.name );
   tio.Flush;
end boom;
-----------


All of that being compiled without even one warning, crashed at
runtime with PROGRAM_ERROR EXCEPTION_ACCESS_VIOLATION  on Windows
( compiled using gnat gpl 2008 )

Modified program  ( Named.Object, being changed to be not limited, and
Some.Object to be Controlled ) runs perfectly.

I have an idea why the program behavs like that, but i think there
must be some warning at least.

What do you think?




^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
                                                                                     ` (2 preceding siblings ...)
  2008-04-23 15:12  6%                                                                   ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-24  0:29  4%                                                                   ` Randy Brukardt
  3 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2008-04-24  0:29 UTC (permalink / raw)


"Georg Bauhaus" <rm.dash-bauhaus@futureapps.de> wrote in message
news:480f1298$0$6782$9b4e6d93@newsspool2.arcor-online.net...
...
> Without of course knowing why the choices were made the
> way they were made for the LRM, my conclusion is that
> many programmers still prefer high school ideas about
> numbers over the theory of computer numbers.

The reason is that the "theory" doesn't match the capabilities of actual
computer hardware.

If you required intermediate results to be checked, integer expressions
would generate 5 times as much code and run only half as fast as they do.
(I'm basing that on the code generated by Janus/Ada, and only considering
operators beyond the first in an expression. It might be possible to do a
bit better, but I've looked at the code generated by other compilers and I
don't think it is wildly different) That wouldn't be competive with other
computer languages.

You could complain that
    X := E'pred(E'succ(C));
isn't different. And indeed I'd agree: it *is* twice as big and
substantially slower than the equivalent
   X := (C + 1) - 1;
would be. It just doesn't matter much because it is rare to use more than
one attribute in an expression, while using multiple integer operators in an
expression is very common.

> Is it really inacceptable to write
>
>    Larger_Type'(Blah + 1) mod 99;
>
> The expression doesn't hide a secret about its
> value range.

There may be no such type, and optimizers transform expressions all of the
time based on the "the correct answer is always OK" rule. It may not be
necessary to evaluate the expression with a larger type. You're essentially
saying that you *don't* want the correct answer in that case, which seems
way too pedantic. I don't think that much code improvement could be done at
all with a strict rule (it's hard to do any as it as, given that overflow
checking prevents a lot of reordering that would be OK in C).

The net effect is that if you want efficient code, you have to relax the
strict rules somewhere. And Ada does that without sacrificing any safety.
(Another similar place is the "invalid" object rules, which allow compilers
to eliminate range checks so long as the value is checked before doing
anything dangerous [like array indexing].)

                                Randy.





^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-23 15:12  6%                                                                   ` Ada.Strings.Bounded Adam Beneschan
  2008-04-23 15:36  6%                                                                     ` Ada.Strings.Bounded (see below)
@ 2008-04-23 17:09  6%                                                                     ` Ray Blaak
  1 sibling, 0 replies; 200+ results
From: Ray Blaak @ 2008-04-23 17:09 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> writes:
> Nahhh, we just want to write programs that work, and have a language
> that helps prevent us from making stupid errors, but without forcing
> us to waste time writing needless junk in order to have things fit
> more consistently into some "theory".  Remember, "theory" is our
> servant, not our master.

Careful. That way lies the path to the dark side: dynamic typing, garbage
collection, interpreted scripts.

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
rAYblaaK@STRIPCAPStelus.net                    The Rhythm has my soul.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 15:12  6%                                                                   ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-23 15:36  6%                                                                     ` (see below)
  2008-04-23 17:09  6%                                                                     ` Ada.Strings.Bounded Ray Blaak
  1 sibling, 0 replies; 200+ results
From: (see below) @ 2008-04-23 15:36 UTC (permalink / raw)


On 23/04/2008 16:12, in article
62dde2ab-d6ad-454b-aa87-8dbc23855903@v23g2000pro.googlegroups.com, "Adam
Beneschan" <adam@irvine.com> wrote:

> On Apr 23, 3:42 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
> wrote:
> 
>> Without of course knowing why the choices were made the
>> way they were made for the LRM, my conclusion is that
>> many programmers still prefer high school ideas about
>> numbers over the theory of computer numbers.
> 
> Nahhh, we just want to write programs that work, and have a language
> that helps prevent us from making stupid errors, but without forcing
> us to waste time writing needless junk in order to have things fit
> more consistently into some "theory".  Remember, "theory" is our
> servant, not our master.

Bravo!
-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
  2008-04-23 12:32  5%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-23 12:52  6%                                                                   ` Ada.Strings.Bounded christoph.grein
@ 2008-04-23 15:12  6%                                                                   ` Adam Beneschan
  2008-04-23 15:36  6%                                                                     ` Ada.Strings.Bounded (see below)
  2008-04-23 17:09  6%                                                                     ` Ada.Strings.Bounded Ray Blaak
  2008-04-24  0:29  4%                                                                   ` Ada.Strings.Bounded Randy Brukardt
  3 siblings, 2 replies; 200+ results
From: Adam Beneschan @ 2008-04-23 15:12 UTC (permalink / raw)


On Apr 23, 3:42 am, Georg Bauhaus <rm.dash-bauh...@futureapps.de>
wrote:

> Without of course knowing why the choices were made the
> way they were made for the LRM, my conclusion is that
> many programmers still prefer high school ideas about
> numbers over the theory of computer numbers.

Nahhh, we just want to write programs that work, and have a language
that helps prevent us from making stupid errors, but without forcing
us to waste time writing needless junk in order to have things fit
more consistently into some "theory".  Remember, "theory" is our
servant, not our master.

                                -- Adam




^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 14:40  6%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-23 15:03  6%                                                                     ` Adam Beneschan
  0 siblings, 0 replies; 200+ results
From: Adam Beneschan @ 2008-04-23 15:03 UTC (permalink / raw)


On Apr 23, 7:40 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On Wed, 23 Apr 2008 13:14:24 +0000 (UTC), Peter Hermann wrote:
> > BTW (changing topic):
> > I am still hoping that the next Ada 2015 will contain
>
> > subtype Number_Base is Integer range 2 .. 36; -- old:16;
>
> You should have asked for more, much MORE!

Right!  Base 36 allows us to use letters from A to Z, instead of just
A to F.  But with Unicode, we now have many, many, many more letters,
so why limit it to 36?  I think it would be great to have a numeric
base that would allow us to encode a numeric literal that includes C
with a hacek, a Tamil letter, some 5th-century Ogham runes, and a
couple Chinese ideographs all in the same literal.  It's obvious that
this would be a very useful feature.

                                -- Adam




^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 13:14  6%                                                                 ` Ada.Strings.Bounded Peter Hermann
@ 2008-04-23 14:40  6%                                                                   ` Dmitry A. Kazakov
  2008-04-23 15:03  6%                                                                     ` Ada.Strings.Bounded Adam Beneschan
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-23 14:40 UTC (permalink / raw)


On Wed, 23 Apr 2008 13:14:24 +0000 (UTC), Peter Hermann wrote:

> BTW (changing topic):
> I am still hoping that the next Ada 2015 will contain
> 
> subtype Number_Base is Integer range 2 .. 36; -- old:16;

You should have asked for more, much MORE! I mean, characters from
identifier_start + number_decimal - '0' (see Ada 2005 RM 2.3). If anybody
needed that thing, of course... (:-))

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 12:52  6%                                                                   ` Ada.Strings.Bounded christoph.grein
@ 2008-04-23 13:34  6%                                                                     ` Georg Bauhaus
  0 siblings, 0 replies; 200+ results
From: Georg Bauhaus @ 2008-04-23 13:34 UTC (permalink / raw)


christoph.grein@eurocopter.com schrieb:
>> procedure Ex is
>>     type E is (A, B, C);
>>     X: E;
>> begin
>>     X := E'pred(E'succ(C));
>> end Ex;
> 
> You can have this:
> 
>   type Enum is (A, B, C, D);
>   type Sub is new Enum range A .. C;
> 
>   Sub'Succ (Sub'Last) = D
>   Sub'Pred (Sub'Succ (Sub'Last)) = C
> 
> Sub'Base has range A .. D.

Yes, but extending the set of values only shifts the
(theoretical) problem of 'Succ by one inductive step.
Once we forget about the type of unrepresentable numbers
the problem ceases to exist, I think.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 20:15  4%                                                               ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-23 13:14  6%                                                                 ` Peter Hermann
  2008-04-23 14:40  6%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Peter Hermann @ 2008-04-23 13:14 UTC (permalink / raw)


Adam Beneschan <adam@irvine.com> wrote:
> was a darn good reason why they did it that way.  In this particular
> case, I think they saw a need to support static expressions with
> intermediate results that were larger than a machine integer, and the

which is one of the many advantages of Ada.

BTW (changing topic):
I am still hoping that the next Ada 2015 will contain

subtype Number_Base is Integer range 2 .. 36; -- old:16;

in Ada.Text_IO for practical reasons, see

www.ada-auth.org/cgi-bin/cvsweb.cgi/ACs/AC-00070.TXT?rev=1.1






^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
  2008-04-23 12:32  5%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-23 12:52  6%                                                                   ` christoph.grein
  2008-04-23 13:34  6%                                                                     ` Ada.Strings.Bounded Georg Bauhaus
  2008-04-23 15:12  6%                                                                   ` Ada.Strings.Bounded Adam Beneschan
  2008-04-24  0:29  4%                                                                   ` Ada.Strings.Bounded Randy Brukardt
  3 siblings, 1 reply; 200+ results
From: christoph.grein @ 2008-04-23 12:52 UTC (permalink / raw)


> procedure Ex is
>     type E is (A, B, C);
>     X: E;
> begin
>     X := E'pred(E'succ(C));
> end Ex;

You can have this:

  type Enum is (A, B, C, D);
  type Sub is new Enum range A .. C;

  Sub'Succ (Sub'Last) = D
  Sub'Pred (Sub'Succ (Sub'Last)) = C

Sub'Base has range A .. D.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
@ 2008-04-23 12:32  5%                                                                   ` Dmitry A. Kazakov
  2008-04-23 12:52  6%                                                                   ` Ada.Strings.Bounded christoph.grein
                                                                                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-23 12:32 UTC (permalink / raw)


On Wed, 23 Apr 2008 12:42:32 +0200, Georg Bauhaus wrote:

> But how about this:
> 
> procedure Ex is
>     type E is (A, B, C);
>     X: E;
> begin
>     X := E'pred(E'succ(C));
> end Ex;
> 
> In this case there is a static constraint error. Is this
> consistent with anything but the Ada LRM's exception for
> "integer convenience"?

But enumeration is finite. If we had extensible enumerations then it would
be reasonable to consider the set of enumeration values infinite, similarly
to signed integers.

Probably it could be possible to formalize such things by allowing the user
to describe certain properties of primitive operations. The case (A + B)
mod C relies on the group property of "+" and "mod":

   forall n   (A + nC) mod C = A mod C

There exists properties Ada compiler knows. For example:

  forall private T, (not X=Y) = (X/=Y)

But it does not know that  X - Y = X + (-Y), etc.

Also, supertyping should help. The anonymous types before the first named
subtype is nothing but a supertype, if you wanted to expose it. In the
cases when the user defines a primitive operation, the stuff like above
could to be defined in terms of the supertype or the class of
(contravariant).

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



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22 19:41  6%                                                               ` Ada.Strings.Bounded Robert A Duff
  2008-04-22 22:55  6%                                                                 ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-23 10:42  6%                                                                 ` Georg Bauhaus
  2008-04-23 12:32  5%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
                                                                                     ` (3 more replies)
  1 sibling, 4 replies; 200+ results
From: Georg Bauhaus @ 2008-04-23 10:42 UTC (permalink / raw)


Robert A Duff schrieb:

>> And so now I have developed a Strong Opinion.  This is a travesty.
> 
> I agree it's confusing.  But "travesty" is too strong.  In practise,
> none of this matters much.
> 
> Don't you want to be able to say "(Blah + 1) mod 99" without overflow
> (where Blah is of subtype X)?

Hmm, less explicit and more lazy programming is
attractive to many programmers, so just write expressions
of a type that cannot be named, just in case of integers.
But how about this:

procedure Ex is
    type E is (A, B, C);
    X: E;
begin
    X := E'pred(E'succ(C));
end Ex;

In this case there is a static constraint error. Is this
consistent with anything but the Ada LRM's exception for
"integer convenience"?

Without of course knowing why the choices were made the
way they were made for the LRM, my conclusion is that
many programmers still prefer high school ideas about
numbers over the theory of computer numbers.

Is it really inacceptable to write

   Larger_Type'(Blah + 1) mod 99;

The expression doesn't hide a secret about its
value range.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-23  6:40  6%                                                                   ` Ada.Strings.Bounded christoph.grein
@ 2008-04-23  6:54  6%                                                                     ` christoph.grein
  0 siblings, 0 replies; 200+ results
From: christoph.grein @ 2008-04-23  6:54 UTC (permalink / raw)


  S: constant := Integer’Last + Integer’Last; -- "+" of Integer
  T: constant := Long_Integer’Last + 1;       -- "+" of Long_Integer
  U: constant := S + T;                       -- "+" of root_integer
  V: constant := S + Long_Integer’Last;       -- "+" of Long_Integer

All of S, T, U, V are of type Universal_Integer.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 22:55  6%                                                                 ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-23  6:40  6%                                                                   ` christoph.grein
  2008-04-23  6:54  6%                                                                     ` Ada.Strings.Bounded christoph.grein
  0 siblings, 1 reply; 200+ results
From: christoph.grein @ 2008-04-23  6:40 UTC (permalink / raw)


When you declare a type

  type T is range 1 .. 10;

the name T denotes the first subtype of the anonymous type of T (the
RM uses T in italics to denote this type, e.g. in 4.5.3, and this type
has the infinite set of mathematical integers).
Thus 11 *is* a value of the type of T (in sloppy language, the type
T).

The static named number

  S: constant := Integer’Last + Integer’Last;

uses the "+" of Integer without overflow and converts the result to
Universal_Integer. Therefore

  S: constant := Integer’Last + Long_Integer’Last;

is not allowed because it mixes two different types, but

  T: constant := Long_Integer’Last;
  U: constant := S + T;

is allowed, the "+" in the last expression being the one of
root_integer.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 19:41  6%                                                               ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-22 22:55  6%                                                                 ` Eric Hughes
  2008-04-23  6:40  6%                                                                   ` Ada.Strings.Bounded christoph.grein
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
  1 sibling, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-22 22:55 UTC (permalink / raw)


On Apr 22, 1:41 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> I agree it's confusing.  But "travesty" is too strong.  In practise,
> none of this matters much.

Definitions matters if you wish to extend them.  These definitions are
not extensible.  I still think it's a travesty.

> Don't you want to be able to say "(Blah + 1) mod 99" without overflow
> (where Blah is of subtype X)?

I can do it without those definitions.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
  2008-04-22 19:19  6%                                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-22 19:41  6%                                                               ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-22 20:15  4%                                                               ` Adam Beneschan
  2008-04-23 13:14  6%                                                                 ` Ada.Strings.Bounded Peter Hermann
  2 siblings, 1 reply; 200+ results
From: Adam Beneschan @ 2008-04-22 20:15 UTC (permalink / raw)


On Apr 22, 11:47 am, Eric Hughes <eric....@gmail.com> wrote:

> So now wait.  When I declare
>     type X is range 0 .. 99 ;
> does that mean that the value 100 is a value of type X?

Yes.  See 3.2.1(6).  This declaration defines both a *type* X and its
*first subtype* X.  The type X includes all integers.  The subtype X
imposes a constraint of 0..99 on that type.  When you declare

    Var : X;

and then assign something into Var, the expression's value will be
checked against the subrange 0..99, just as if you had said

    type Y is range 0..1_000_000_000;
    subtype YY is Y range 0..99;

    Var : YY;

> And so now I have developed a Strong Opinion.  This is a travesty.  A
> probably-irredeemable travesty. This is so completely counter-
> intuitive that I have a hard time believing that competent people came
> up with this way of writing the definition.  It's unnecessary.  There
> are far better ways of defining this, and they don't break any
> existing syntax.

Back on April 15, in a different thread, you said "Make the formal
standard normative, the human language expository", arguing that it
would be OK for the formal standard to be inaccessible to human
programmers.  Now, in a case where the formal standard has been made a
little bit complex in order to get the language to work they way they
wanted it to work, then you complain about it not being intuitive.  I
don't think you can have it both ways.

But I am going to complain bitterly about one thing: you are way out
of line to insinuate that the people who came up with the standard are
incompetent.  WAY out of line.  I know how much work the people who
work on the standard put into it, and how much thought they put into
making sure everything fits together and all the bases are covered
while at the same time trying to make it reasonably readable.  So even
if you don't understand why the standard's authors defined something
the way they did, you can assume there's a 99.9999% chance that there
was a darn good reason why they did it that way.  In this particular
case, I think they saw a need to support static expressions with
intermediate results that were larger than a machine integer, and the
type/subtype definitions they came up with allowed them to accomplish
this.

                                 -- Adam






^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
  2008-04-22 17:49  6%                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-22 19:56  5%                                                             ` Adam Beneschan
  2 siblings, 0 replies; 200+ results
From: Adam Beneschan @ 2008-04-22 19:56 UTC (permalink / raw)


On Apr 22, 8:41 am, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:

> Also, there's a rule (which I'm too lazy to look up right now),
> which says that at run time, the compiler is always allowed to get the
> right answer.

You may be thinking of 4.5(13), which allows the compiler to reorder
operators at the same precedence level, so that in:

   X : Integer := Some_Function_Call (...);
   Y : Integer := (X + 1) - 1;

assuming "+" and "-" haven't been overridden, it's permissible for the
compiler to change the last expression to X + (1 - 1) which becomes
simply X, and thus not raise Constraint_Error even if
Some_Function_Call returns Integer'Last.  However, I don't know that
this *always* allows the compiler to get the right answer:

    X : Positive := Some_Function_Call (...);
    Y : Positive := X**2 / X;

The implementation permission wouldn't apply since the two operators
involved in Y's initialization aren't at the same precedence level,
and I don't know that there's anything else in the RM that would allow
the compiler to avoid raising Constraint_Error if X**2 is too large.
Also, I don't see how that rule would let the compiler avoid doing the
multiplication in something like

    Y : Integer := (X * X) - (X * X);

4.5(13) is pretty limited in its application, and I don't think
there's a general principle that the compiler is always allowed to
figure out the mathematically correct result in *all* cases without
regard to internal overflows.  Maybe there's such a rule somewhere
else, but I don't know where.  Neither of the permissions in 11.6 are
relevant here, I think.

                               -- Adam



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
  2008-04-22 19:19  6%                                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-22 19:41  6%                                                               ` Robert A Duff
  2008-04-22 22:55  6%                                                                 ` Ada.Strings.Bounded Eric Hughes
  2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
  2008-04-22 20:15  4%                                                               ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 2 replies; 200+ results
From: Robert A Duff @ 2008-04-22 19:41 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 22, 9:41 am, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> The above-quoted paragraph 3.5.4(8) is normative.  It comes right out
>> and says in plain language exactly what you were trying to prove in a
>> circuitous manner -- that the the set of values is infinite.
>
> Here's the relevant sentence in 3.5.4(8) again:
>> The set of values for a signed integer type is the (infinite) set
>> of mathematical integers, though only values of the base range of
>> the type are fully supported for run-time operations.
>
> So now wait.  When I declare
>     type X is range 0 .. 99 ;
> does that mean that the value 100 is a value of type X?

Yes, if you're using "type X" as I explained in my other message to mean
"the type whose first subtype is X".

Subtype X has the range you expect (0..99).  But it has an underlying
type that has all the integer values, including 100.

Note that you could say:

    subtype S is X'Base range 0..100;

>...Because how
> that definition reads in any sort of facially-reasonable way is that
> 100 is not a value of type X.

100 is not a value of SUBtype X.

>> Note that it does not say anything special about root_int or univ_int.
>> It applies to ALL signed integer types, including user-defined ones.
>
> Apparently so.
>
> And so now I have developed a Strong Opinion.  This is a travesty.

I agree it's confusing.  But "travesty" is too strong.  In practise,
none of this matters much.

Don't you want to be able to say "(Blah + 1) mod 99" without overflow
(where Blah is of subtype X)?

- Bob



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-22 19:19  6%                                                               ` Dmitry A. Kazakov
  2008-04-22 19:41  6%                                                               ` Ada.Strings.Bounded Robert A Duff
  2008-04-22 20:15  4%                                                               ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-22 19:19 UTC (permalink / raw)


On Tue, 22 Apr 2008 11:47:05 -0700 (PDT), Eric Hughes wrote:

> And so now I have developed a Strong Opinion.  This is a travesty.  A
> probably-irredeemable travesty. This is so completely counter-
> intuitive that I have a hard time believing that competent people came
> up with this way of writing the definition.  It's unnecessary.  There
> are far better ways of defining this, and they don't break any
> existing syntax.
> 
> I'm out.  Completely out.  Everything I've said has been predicated on
> the assumption that the set of values of a type is what the
> declaration says it is, rather than having values that cannot be
> assigned to a variable of that type.  In my opinion this means that
> assignment and variable definition are broken.  I don't even care what
> the details are at this point.

Well, there are reasons why:

1. Integer types are thought as models for mathematical numbers. The range
is a constraint put on the set value.

2. This allows to skip a lot of checks when the implementation type is
larger than the range. Otherwise, the compiler would be forced to check
each intermediate result in order to raise Constraint_Error.

3. It is rather intuitive, normally one expects to get the right result,
independently on the intermediate results. Moreover, the compiler might
optimize the code choosing a different computation path, so long the result
is mathematically correct.

4. It makes programming less tedious, when values close to the range ends
are involved.

The only real disadvantage I see, is that the program might get
non-portable if programmers actively exploit 4.

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 18:26  6%                                                               ` Ada.Strings.Bounded Samuel Tardieu
@ 2008-04-22 18:59  6%                                                                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-22 18:59 UTC (permalink / raw)


On Tue, 22 Apr 2008 20:26:31 +0200, Samuel Tardieu wrote:

>>>>>> "Dmitry" == Dmitry A Kazakov <mailbox@dmitry-kazakov.de> writes:
> 
> Dmitry> If compilable. The following should break GNAT GPL 2007:
> 
> It doesn't break GCC 4.4.0:
> 
> % gnatmake -g -O2 t
> gcc -c -g -O2 t.adb
> gnatbind -x t.ali
> gnatlink t.ali -g
> 
> % ./t
>  2147483647
> 
> The file I used is on http://www.rfc1149.net/tmp/t.adb if you want to
> try it yourself :)

Well, it seems I miscalculated the number of lines. But actually not too
much, I have added 30 lines to each summand and got the infamous: GNAT BUG
DETECTED ... GPL 2007 (20070405-41) (i586-pc-mingw32msv) Storage_Error heap
exhausted [*]... However it is not a bug of course. In simpler cases like:

   M : constant := 2**1_000_000;

GNAT gives reasonable: "static value too large, capacity exceeded"

---------------
*  In case that would not help (I don't know how many terabytes of memory
you have (:-)), double the number of lines in each summand. Continue so
until the Easter egg reveal itself...

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
  2008-04-22 17:49  6%                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-22 18:47  5%                                                             ` Eric Hughes
  2008-04-22 19:19  6%                                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
                                                                                 ` (2 more replies)
  2008-04-22 19:56  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 3 replies; 200+ results
From: Eric Hughes @ 2008-04-22 18:47 UTC (permalink / raw)


On Apr 22, 9:41 am, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> The above-quoted paragraph 3.5.4(8) is normative.  It comes right out
> and says in plain language exactly what you were trying to prove in a
> circuitous manner -- that the the set of values is infinite.

Here's the relevant sentence in 3.5.4(8) again:
> The set of values for a signed integer type is the (infinite) set
> of mathematical integers, though only values of the base range of
> the type are fully supported for run-time operations.

So now wait.  When I declare
    type X is range 0 .. 99 ;
does that mean that the value 100 is a value of type X?  Because how
that definition reads in any sort of facially-reasonable way is that
100 is not a value of type X.

> Note that it does not say anything special about root_int or univ_int.
> It applies to ALL signed integer types, including user-defined ones.

Apparently so.

And so now I have developed a Strong Opinion.  This is a travesty.  A
probably-irredeemable travesty. This is so completely counter-
intuitive that I have a hard time believing that competent people came
up with this way of writing the definition.  It's unnecessary.  There
are far better ways of defining this, and they don't break any
existing syntax.

I'm out.  Completely out.  Everything I've said has been predicated on
the assumption that the set of values of a type is what the
declaration says it is, rather than having values that cannot be
assigned to a variable of that type.  In my opinion this means that
assignment and variable definition are broken.  I don't even care what
the details are at this point.

Eric



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22 17:49  6%                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-22 18:26  6%                                                               ` Samuel Tardieu
  2008-04-22 18:59  6%                                                                 ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Samuel Tardieu @ 2008-04-22 18:26 UTC (permalink / raw)


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

Dmitry> If compilable. The following should break GNAT GPL 2007:

It doesn't break GCC 4.4.0:

% gnatmake -g -O2 t
gcc -c -g -O2 t.adb
gnatbind -x t.ali
gnatlink t.ali -g

% ./t
 2147483647

The file I used is on http://www.rfc1149.net/tmp/t.adb if you want to
try it yourself :)

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-22 17:49  6%                                                             ` Dmitry A. Kazakov
  2008-04-22 18:26  6%                                                               ` Ada.Strings.Bounded Samuel Tardieu
  2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
  2008-04-22 19:56  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-22 17:49 UTC (permalink / raw)


On Tue, 22 Apr 2008 11:41:29 -0400, Robert A Duff wrote:

> For static expressions, "+" is not a partial function.

If compilable. The following should break GNAT GPL 2007:

with Ada.Text_IO;  use Ada.Text_IO;

procedure Test_Int is
   L : constant Integer := Integer'Last;
   M : constant Integer :=
(L + 
   L*L*L*L ... *L  -- 40 times per line
 *L*L*L*L ... *L 
 ...                    -- 200 lines should be enough
 *L*L*L*L ... *L 
)
-  L*L*L*L ... *L  -- Same as above
 *L*L*L*L ... *L 
 ...
 *L*L*L*L ... *L 
;
begin
   Put_Line (Integer'Image (M));
end Test_Int;

Here we have approximately L + 2**(32*8000) - 2**(32*8000).
-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22 15:30  6%                                                               ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-22 16:08  5%                                                                 ` Robert A Duff
  0 siblings, 0 replies; 200+ results
From: Robert A Duff @ 2008-04-22 16:08 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 21, 7:02 pm, Adam Beneschan <a...@irvine.com> wrote:
>> The expected type is Z; therefore, in
>> example C, the only possible meaning for "-" is the function that
>> takes two arguments of type Z and returns Z.  That, in turn, applies
>> to "+". So it's 100% clear from the language rules what functions are
>> called by this expression.  The reason it doesn't raise
>> Constraint_Error is 4.9(33), as I mentioned earlier.
>
> OK.  But then what's the type of the subexpression "( Z0 + 1 )" within
> the static expression "( Z0 + 1 ) - 1"?  It can't be of type Z, since
> it's outside the bounds of type Z.  And the addition chosen can't be
> the same addition as the declared one, which returns Z, and that
> subexpression returns something that's not in Z.

Ah, I see what might be confusing you.  You need to understand the
difference between types and subtypes.  When you say:

    type Z is range ...;

you are declaring a type and a subtype (the "first subtype").  The name
Z refers to the firts subtype, and has the specified range.  There is no
way to refer to the type by name.  Strange, but true!  When I say "the
type Z", I really mean "the type whose first subtype is Z".
The RM sometimes uses the term "the type of subtype Z".

The operators of the type Z can return results outside the range of Z.
                     ^^^^^^
                     note sloppy/informal wording!

Consider:

    type T is range 1..10;
    A : T := Read_From_Keyboard;
    B : T := Read_From_Keyboard;
    C : T := (A - 1) + B;

Imagine Read_From_Keyboard reads a number between 1 and 10,
and suppose we happen to get A = 1, and B = 5.  C must equal
5, even though the intermediate result A-1 is out of range
for T.

The "base subtype", called T'Base, has an implementation-defined range,
which covers at least -10..10, but might well be something like
-2**31..2**31-1.  At run time, operators will get the right
answer if it's in the base range.  If it's outside the base
range, the compiler is ALLOWED to get the right answer, but
is also allowed to overflow.

>...  The addition used
> here has a different signature.
>
> It seems that the overload resolution rules don't apply when
> universal_integer is involved.  This seems a pretty obvious
> consequence of 4.9(33).

No, it's false, and is therefore obviously NOT a consequence of
4.9(33)!  ;-)

There are some special rules for univ_int (mainly, the implicit
conversions), but the rules apply.

- Bob



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22 15:25  5%                                                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-22 15:54  5%                                                               ` Robert A Duff
  0 siblings, 0 replies; 200+ results
From: Robert A Duff @ 2008-04-22 15:54 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 21, 6:49 pm, Adam Beneschan <a...@irvine.com> wrote:
>> See 4.9(33).
>
> Oh.  OK.  For those insufficiently motivated to look at this section,
> it says that static expressions are evaluated exactly, without
> performing overflow checks.

Right.

>...To me, that word "exactly" means that
> static expressions are evaluated as universal_integer, since that's
> the only way to get them defined exactly.

No, that does not follow.  It says they are evaluated exactly,
which means the compiler must get the right answer, according
to the normal rules of integer math.  That has nothing to do
with univ_int.

> Previously, Bob Duff had said:
>> An integer literal has type universal_integer, as you said, but
>> universal_integer has no "+" operator.  There is a "+" for root_integer,
>> and also for user-defined integer types.  Universal_integers can be
>> implicitly converted to various integer types.
>
> Something's got to give here.  I see the following possibilities:
> 1) universal_integer actually does have a "+" operator.

It does not.  It doesn't need them, since univ_int can be implicitly
converted to any other integer type.  And if univ_int had operators,
lots of useful expressions would be ambiguous, and therefore illegal!

>...It would only
> be available at compile time, since there's no way to declare a
> variable of type universal_integer.

However, there are some fairly obscure ways to write nonstatic
expressions of type universal_integer, and pass those to
the operators of type root_integer, at run time.  These will
get overflows -- Constraint_Error if the value doesn't fit in
the base range of root_int (the 64-bit range, for GNAT).

> 2) The addition chosen is the context-dependent one, as for dynamic
> expressions, but when overflow happens, the result is magically
> converted to universal_integer.

No.

> 3) The addition of the ordinary type is tried with the base type.  If
> it overflows, a bigger type is tried, and so on up to
> universal_integer, which will always succeed.

No.

> 4) The evaluation happens purely mathematically, without regard for
> the Ada type system.

Yes.  That is, the "+" operator of all types behaves that way in static
expressions.

> 5) There are different versions of the type and its addition operation
> for static and run-time use.  The static ones have arbitrarily large
> capacity and exact arithmetic.

Sort of.  I wouldn't call it "different versions of the type", though.
The operators behave differently in static expressions than at run
time.  There's nothing special about the root_int ops in this regard
(and there are no univ_int ops).

> I'm sure my imagination is not large enough to guess at all the
> possibilities.  What's going on here, really?

I hope my comments above answer that question!  ;-)

- Bob



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22  0:19  3%                                                         ` Ada.Strings.Bounded Eric Hughes
  2008-04-22  0:49  6%                                                           ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-22 15:41  4%                                                           ` Robert A Duff
  2008-04-22 17:49  6%                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
                                                                               ` (2 more replies)
  1 sibling, 3 replies; 200+ results
From: Robert A Duff @ 2008-04-22 15:41 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 21, 12:04 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> We all know there are an infinite number of integers, so why did
>> you want to prove it?
>
> The question was not about {\bb N}, but about universal_integer, which
> two things are not _a priori_ the same thing.
>
>> Sure.  But I don't see the need for all this song and dance,
>> since AARM-3.5.4 says:
>>
>> 8     The set of values for a signed integer type is the (infinite) set of
>> mathematical integers[, though only values of the base range of the type are
>> fully supported for run-time operations]. The set of values for a modular
>> integer type are the values from 0 to one less than the modulus, inclusive.
>
> The argument was being made against the counter-assertion that
> universal_integer is an ordinary integer type and thus has a finite
> range.  And I wanted to make that argument from normative sources, not
> from commentary.

The above-quoted paragraph 3.5.4(8) is normative.  It comes right out
and says in plain language exactly what you were trying to prove in a
circuitous manner -- that the the set of values is infinite.

Note that it does not say anything special about root_int or univ_int.
It applies to ALL signed integer types, including user-defined ones.

You should read about static expressions, which will clear up some of
your confusings below.  You should also make sure you understand the
difference between overflow checks and range checks.

Also, there's a rule (which I'm too lazy to look up right now),
which says that at run time, the compiler is always allowed to get the
right answer.

So for a static expression that is outside the base range of its type,
the compiler must calculate the right answer.  For a non-static
expression, the compiler may raise Constraint_Error if the value is
outside the base range, or it may choose to get the right mathematical
answer.  It can even roll dice to decide whether to get the right
answer.

>> But you could rely on integer addition (for static values of type
>> root_integer, for example).
>
> Could I?  I'm not so sure.  If root_integer is a range, as ordinary
> defined integer types are, then "+" is a partial function and not a
> total one, breaking the argument.

No, the semantics of "+" are different depending on whether the
expression is static.  NOT depending on whether the type is root_int.
For static expressions, "+" is not a partial function.

> Bob's example:
>> type My_Int is range 1..100;
>> Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
>>                               -- Y is of type My_Int.
>
> Me:
>> > Are there other places in Ada when the context of an operation
>> > determines the type of the operands of the function and thus also the
>> > function signature?
>
>> Overload resolution always takes the context into account,
>> for function calls.  Nothing special about "+" in that regard.
>> If you say:
>>
>>     P(Param => F(X));
>>
>> Then the type of Param helps determine which F is called
>
> OK.  Somehow I had missed the fact that Ada does overload resolution
> based on assignment context.  So I read up on it in more detail.
> Pardon me if I've missed something in the foregoing.
>
> The overload resolution in the present example, though, doesn't seem
> unique.  Could not "+" resolve to the "+" of root_integer?

No.  The "+" of root_integer returns root_integer, and there is no
implicit conversion from root_integer to My_Int, so the "+" of
root_integer can't be used in the above example.

>...It seems
> to pass all of the requirements.  To test this, I wrote the following
> three lines of code and ran them through GNAT:
>     -- (Example A)
>     Z0 : constant := Integer'Last - 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> GNAT compiled it without a problem and it ran without error.  The
> following program, however, did neither:
>     -- (Example B)
>     Z0 : constant := Integer'Last - 1 ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT gave a warning that a constraint error would be raised and indeed
> running it raised one.  Now I raise the upper bound by one:
>     -- (Example C)
>     Z0 : constant := Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> GNAT compiles this one fine and runs fine, just like Example A.
>     -- (Example D)
>     Z0 : constant := Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT says "static expression fails Constraint_Check" and does not
> compile.  Let's raise the upper bound one last time:
>     -- (Example E)
>     Z0 : constant := Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> Just fine, as usual.
>     -- (Example F)
>     Z0 : constant := Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT gives the same warning as example B.
>
> As an aside, GNAT is clearly doing something odd.

It is obeying the language rules.  You might say the language rules are
odd, and I would agree.  I don't much like the fact that static
expressions have subtly different evaluation rules from normal
run-time calculations.

>...Of the three
> declarations of "C", you have two warnings and one error, not the
> same.  I'm not even sure that's a defect.

It's not a defect in GNAT -- read the section on static expressions.

> The real point, though, is that it just can't be true that the
> addition and subtraction in examples A and C are those of type Z.  If
> this were true, the expression
>     ( Z0 + 1 ) - 1
> should translate to something like this:
>     Z_subtract( Z_add( Z0, 1 ), 1 )
> If that were the case, then the Z_add expression should raise a
> constraint error.

No.  Static expressions cannot overflow.  The "+" used in those two
examples is that of type Z.

Note that the "-" that occurs in some of your declarations of Z0 is the
"-" on root_integer.  Look at the special rules for named numbers in
3.3.2, and the special preference rule in 8.6(29).  But 8.6(29) has
nothing to do with the B and C constants in your examples.

>...It doesn't.  Maybe this is a GNAT defect.

No.

>...It seems
> just as likely that overload resolution is taking the addition and
> subtraction of root_integer.

No, as I explained, that "+" and "-" return the wrong type!

> And then I had an inspiration:
>     -- (Example G)
>     Z0 : constant := Long_Long_Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
>     -- (Example H)
>     Z0 : constant := Long_Long_Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> Now we've hit the GNAT implementation limit.

Right.  Note that it complains about type Z, not about the named number
Z0.  GNAT is not allowed to complain about Z0 in Example H.

>...Example H, finally,
> fails to compile because "integer type definition bounds out of
> range".  (I don't like this message because it's not clear that an
> internal limit has been exceeded.)

A fair complaint.

>...Example G, however, compiles and
> runs just fine.  Example G shows that, at least in this example, it's
> doing arithmetic on universal_integer, because there's no other type
> internally that it could be using.

No.  It is using the "+" on Z.  There is no "+" on universal_integer,
and the one on root_integer has the wrong result type.

>> Choosing which function to call nondeterministically seems
>> like an Obviously Bad Idea, to me, so perhaps I don't understand
>> what you mean.
>
> All the above examples seem to indicate that GNAT, at least, is
> resolving overloaded addition operators.  The overload is between the
> declared type, root_integer (or something like it), and possibly even
> universal_integer.  With other types, ones where there is no universal
> type, this would be an illegal ambiguity.  So it seems that GNAT is
> nondeterministically resolving them.

No.  There is no nondeterministic overload resolution in Ada.

> It works here because all these types are compatible for such
> resolution.  It doesn't cause any problems.  This is what I believe
> could be declared explicitly.

Well, in the last sentence, "This" refers to some incorrect
interpretations of some (annoyingly complicated) Ada language rules,
so I still don't know what you mean (sorry).

- Bob



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-22  1:02  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-22 15:30  6%                                                               ` Eric Hughes
  2008-04-22 16:08  5%                                                                 ` Ada.Strings.Bounded Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-22 15:30 UTC (permalink / raw)


On Apr 21, 7:02 pm, Adam Beneschan <a...@irvine.com> wrote:
> The expected type is Z; therefore, in
> example C, the only possible meaning for "-" is the function that
> takes two arguments of type Z and returns Z.  That, in turn, applies
> to "+". So it's 100% clear from the language rules what functions are
> called by this expression.  The reason it doesn't raise
> Constraint_Error is 4.9(33), as I mentioned earlier.

OK.  But then what's the type of the subexpression "( Z0 + 1 )" within
the static expression "( Z0 + 1 ) - 1"?  It can't be of type Z, since
it's outside the bounds of type Z.  And the addition chosen can't be
the same addition as the declared one, which returns Z, and that
subexpression returns something that's not in Z.  The addition used
here has a different signature.

It seems that the overload resolution rules don't apply when
universal_integer is involved.  This seems a pretty obvious
consequence of 4.9(33).

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-22  0:49  6%                                                           ` Ada.Strings.Bounded Adam Beneschan
  2008-04-22  1:02  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-22 15:25  5%                                                             ` Eric Hughes
  2008-04-22 15:54  5%                                                               ` Ada.Strings.Bounded Robert A Duff
  1 sibling, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-22 15:25 UTC (permalink / raw)


On Apr 21, 6:49 pm, Adam Beneschan <a...@irvine.com> wrote:
> See 4.9(33).

Oh.  OK.  For those insufficiently motivated to look at this section,
it says that static expressions are evaluated exactly, without
performing overflow checks.  To me, that word "exactly" means that
static expressions are evaluated as universal_integer, since that's
the only way to get them defined exactly.

Previously, Bob Duff had said:
> An integer literal has type universal_integer, as you said, but
> universal_integer has no "+" operator.  There is a "+" for root_integer,
> and also for user-defined integer types.  Universal_integers can be
> implicitly converted to various integer types.

Something's got to give here.  I see the following possibilities:
1) universal_integer actually does have a "+" operator.  It would only
be available at compile time, since there's no way to declare a
variable of type universal_integer.
2) The addition chosen is the context-dependent one, as for dynamic
expressions, but when overflow happens, the result is magically
converted to universal_integer.
3) The addition of the ordinary type is tried with the base type.  If
it overflows, a bigger type is tried, and so on up to
universal_integer, which will always succeed.
4) The evaluation happens purely mathematically, without regard for
the Ada type system.
5) There are different versions of the type and its addition operation
for static and run-time use.  The static ones have arbitrarily large
capacity and exact arithmetic.

I'm sure my imagination is not large enough to guess at all the
possibilities.  What's going on here, really?

Eric



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22  0:49  6%                                                           ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-22  1:02  5%                                                             ` Adam Beneschan
  2008-04-22 15:30  6%                                                               ` Ada.Strings.Bounded Eric Hughes
  2008-04-22 15:25  5%                                                             ` Ada.Strings.Bounded Eric Hughes
  1 sibling, 1 reply; 200+ results
From: Adam Beneschan @ 2008-04-22  1:02 UTC (permalink / raw)


On Apr 21, 5:49 pm, Adam Beneschan <a...@irvine.com> wrote:

> >     -- (Example C)
> >     Z0 : constant := Integer'Last ;
> >     type Z is range 0 .. Z0 ;
> >     B : constant Z := ( Z0 + 1 ) - 1 ;

> > All the above examples seem to indicate that GNAT, at least, is
> > resolving overloaded addition operators.  The overload is between the
> > declared type, root_integer (or something like it), and possibly even
> > universal_integer.  With other types, ones where there is no universal
> > type, this would be an illegal ambiguity.  So it seems that GNAT is
> > nondeterministically resolving them.
>
> There's nothing nondeterministic about this.  See 8.6(29).

I goofed.  This rule doesn't actually apply in this case, since the
expected type of the expression is a user-defined integer type, which
isn't compatible with root_integer.  (If the expected type of an
expression is a specific integer type that isn't root_integer, the
expression can be of that type or it can be universal_integer, but it
can't be root_integer.)  I've sometimes made the mistake of confusing
root_ and universal_integer, and I got sloppy here.

But I think that actually makes the point even moreso that there's no
nondeterminism involved.  The expected type is Z; therefore, in
example C, the only possible meaning for "-" is the function that
takes two arguments of type Z and returns Z.  That, in turn, applies
to "+".  So it's 100% clear from the language rules what functions are
called by this expression.  The reason it doesn't raise
Constraint_Error is 4.9(33), as I mentioned earlier.

                                 -- Adam




^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-22  0:19  3%                                                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-22  0:49  6%                                                           ` Adam Beneschan
  2008-04-22  1:02  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
  2008-04-22 15:25  5%                                                             ` Ada.Strings.Bounded Eric Hughes
  2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
  1 sibling, 2 replies; 200+ results
From: Adam Beneschan @ 2008-04-22  0:49 UTC (permalink / raw)


On Apr 21, 5:19 pm, Eric Hughes <eric....@gmail.com> wrote:

> OK.  Somehow I had missed the fact that Ada does overload resolution
> based on assignment context.  So I read up on it in more detail.
> Pardon me if I've missed something in the foregoing.
>
> The overload resolution in the present example, though, doesn't seem
> unique.  Could not "+" resolve to the "+" of root_integer?  It seems
> to pass all of the requirements.  To test this, I wrote the following
> three lines of code and ran them through GNAT:
>     -- (Example A)
>     Z0 : constant := Integer'Last - 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> GNAT compiled it without a problem and it ran without error.  The
> following program, however, did neither:
>     -- (Example B)
>     Z0 : constant := Integer'Last - 1 ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT gave a warning that a constraint error would be raised and indeed
> running it raised one.  Now I raise the upper bound by one:
>     -- (Example C)
>     Z0 : constant := Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> GNAT compiles this one fine and runs fine, just like Example A.
>     -- (Example D)
>     Z0 : constant := Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT says "static expression fails Constraint_Check" and does not
> compile.  Let's raise the upper bound one last time:
>     -- (Example E)
>     Z0 : constant := Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> Just fine, as usual.
>     -- (Example F)
>     Z0 : constant := Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     C : constant Z := Z0 + 1 ;
> GNAT gives the same warning as example B.
>
> As an aside, GNAT is clearly doing something odd.  Of the three
> declarations of "C", you have two warnings and one error, not the
> same.  I'm not even sure that's a defect.
>
> The real point, though, is that it just can't be true that the
> addition and subtraction in examples A and C are those of type Z.  If
> this were true, the expression
>     ( Z0 + 1 ) - 1
> should translate to something like this:
>     Z_subtract( Z_add( Z0, 1 ), 1 )
> If that were the case, then the Z_add expression should raise a
> constraint error.  It doesn't.  Maybe this is a GNAT defect.  It seems
> just as likely that overload resolution is taking the addition and
> subtraction of root_integer.

See 4.9(33).  I'm not sure it applies in this case, though, since the
root_integer operations will be preferred (see below).  But note that
this compiles and will not cause Constraint_Error to be raised:

   A1 : constant Integer := Integer'Last;
   A2 : constant Integer := (A1 + 1) - 1;


> And then I had an inspiration:
>     -- (Example G)
>     Z0 : constant := Long_Long_Integer'Last ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
>     -- (Example H)
>     Z0 : constant := Long_Long_Integer'Last + 1 ;
>     type Z is range 0 .. Z0 ;
>     B : constant Z := ( Z0 + 1 ) - 1 ;
> Now we've hit the GNAT implementation limit.  Example H, finally,
> fails to compile because "integer type definition bounds out of
> range".  (I don't like this message because it's not clear that an
> internal limit has been exceeded.)  Example G, however, compiles and
> runs just fine.  Example G shows that, at least in this example, it's
> doing arithmetic on universal_integer, because there's no other type
> internally that it could be using.
>
> > Choosing which function to call nondeterministically seems
> > like an Obviously Bad Idea, to me, so perhaps I don't understand
> > what you mean.
>
> All the above examples seem to indicate that GNAT, at least, is
> resolving overloaded addition operators.  The overload is between the
> declared type, root_integer (or something like it), and possibly even
> universal_integer.  With other types, ones where there is no universal
> type, this would be an illegal ambiguity.  So it seems that GNAT is
> nondeterministically resolving them.

There's nothing nondeterministic about this.  See 8.6(29).

I can't follow your argument so I have no idea whether these points
affect it or not.  But you do seem to have made at least a couple
mistakes about the language.

                                 -- Adam




^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-21 18:50  5%                                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-22  0:31  6%                                                         ` Eric Hughes
  0 siblings, 0 replies; 200+ results
From: Eric Hughes @ 2008-04-22  0:31 UTC (permalink / raw)


> On Mon, 21 Apr 2008 09:35:36 -0700 (PDT), Eric Hughes wrote:
> > ARM 2.4.1 "Decimal Literals"
> > has no length limitation on 'numeral'.

On Apr 21, 12:50 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Hmm, I don't see it saying this. Do you mean that the syntax rule specifies
> not limit?

That's right.  The language places no limit on the length of
numerals.  See Bob Duff's "nit" for a qualification.  Every compiler
will have some limit, but that doesn't affect the language definition.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-21 18:04  4%                                                       ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-22  0:19  3%                                                         ` Eric Hughes
  2008-04-22  0:49  6%                                                           ` Ada.Strings.Bounded Adam Beneschan
  2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
  0 siblings, 2 replies; 200+ results
From: Eric Hughes @ 2008-04-22  0:19 UTC (permalink / raw)


On Apr 21, 12:04 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> We all know there are an infinite number of integers, so why did
> you want to prove it?

The question was not about {\bb N}, but about universal_integer, which
two things are not _a priori_ the same thing.

> Sure.  But I don't see the need for all this song and dance,
> since AARM-3.5.4 says:
>
> 8     The set of values for a signed integer type is the (infinite) set of
> mathematical integers[, though only values of the base range of the type are
> fully supported for run-time operations]. The set of values for a modular
> integer type are the values from 0 to one less than the modulus, inclusive.

The argument was being made against the counter-assertion that
universal_integer is an ordinary integer type and thus has a finite
range.  And I wanted to make that argument from normative sources, not
from commentary.

> But you could rely on integer addition (for static values of type
> root_integer, for example).

Could I?  I'm not so sure.  If root_integer is a range, as ordinary
defined integer types are, then "+" is a partial function and not a
total one, breaking the argument.

Bob's example:
> type My_Int is range 1..100;
> Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
>                               -- Y is of type My_Int.

Me:
> > Are there other places in Ada when the context of an operation
> > determines the type of the operands of the function and thus also the
> > function signature?

> Overload resolution always takes the context into account,
> for function calls.  Nothing special about "+" in that regard.
> If you say:
>
>     P(Param => F(X));
>
> Then the type of Param helps determine which F is called

OK.  Somehow I had missed the fact that Ada does overload resolution
based on assignment context.  So I read up on it in more detail.
Pardon me if I've missed something in the foregoing.

The overload resolution in the present example, though, doesn't seem
unique.  Could not "+" resolve to the "+" of root_integer?  It seems
to pass all of the requirements.  To test this, I wrote the following
three lines of code and ran them through GNAT:
    -- (Example A)
    Z0 : constant := Integer'Last - 1 ;
    type Z is range 0 .. Z0 ;
    B : constant Z := ( Z0 + 1 ) - 1 ;
GNAT compiled it without a problem and it ran without error.  The
following program, however, did neither:
    -- (Example B)
    Z0 : constant := Integer'Last - 1 ;
    type Z is range 0 .. Z0 ;
    C : constant Z := Z0 + 1 ;
GNAT gave a warning that a constraint error would be raised and indeed
running it raised one.  Now I raise the upper bound by one:
    -- (Example C)
    Z0 : constant := Integer'Last ;
    type Z is range 0 .. Z0 ;
    B : constant Z := ( Z0 + 1 ) - 1 ;
GNAT compiles this one fine and runs fine, just like Example A.
    -- (Example D)
    Z0 : constant := Integer'Last ;
    type Z is range 0 .. Z0 ;
    C : constant Z := Z0 + 1 ;
GNAT says "static expression fails Constraint_Check" and does not
compile.  Let's raise the upper bound one last time:
    -- (Example E)
    Z0 : constant := Integer'Last + 1 ;
    type Z is range 0 .. Z0 ;
    B : constant Z := ( Z0 + 1 ) - 1 ;
Just fine, as usual.
    -- (Example F)
    Z0 : constant := Integer'Last + 1 ;
    type Z is range 0 .. Z0 ;
    C : constant Z := Z0 + 1 ;
GNAT gives the same warning as example B.

As an aside, GNAT is clearly doing something odd.  Of the three
declarations of "C", you have two warnings and one error, not the
same.  I'm not even sure that's a defect.

The real point, though, is that it just can't be true that the
addition and subtraction in examples A and C are those of type Z.  If
this were true, the expression
    ( Z0 + 1 ) - 1
should translate to something like this:
    Z_subtract( Z_add( Z0, 1 ), 1 )
If that were the case, then the Z_add expression should raise a
constraint error.  It doesn't.  Maybe this is a GNAT defect.  It seems
just as likely that overload resolution is taking the addition and
subtraction of root_integer.

And then I had an inspiration:
    -- (Example G)
    Z0 : constant := Long_Long_Integer'Last ;
    type Z is range 0 .. Z0 ;
    B : constant Z := ( Z0 + 1 ) - 1 ;
    -- (Example H)
    Z0 : constant := Long_Long_Integer'Last + 1 ;
    type Z is range 0 .. Z0 ;
    B : constant Z := ( Z0 + 1 ) - 1 ;
Now we've hit the GNAT implementation limit.  Example H, finally,
fails to compile because "integer type definition bounds out of
range".  (I don't like this message because it's not clear that an
internal limit has been exceeded.)  Example G, however, compiles and
runs just fine.  Example G shows that, at least in this example, it's
doing arithmetic on universal_integer, because there's no other type
internally that it could be using.

> Choosing which function to call nondeterministically seems
> like an Obviously Bad Idea, to me, so perhaps I don't understand
> what you mean.

All the above examples seem to indicate that GNAT, at least, is
resolving overloaded addition operators.  The overload is between the
declared type, root_integer (or something like it), and possibly even
universal_integer.  With other types, ones where there is no universal
type, this would be an illegal ambiguity.  So it seems that GNAT is
nondeterministically resolving them.

It works here because all these types are compatible for such
resolution.  It doesn't cause any problems.  This is what I believe
could be declared explicitly.

Eric




^ permalink raw reply	[relevance 3%]

* Re: Ada.Strings.Bounded
  2008-04-21 16:35  3%                                                     ` Ada.Strings.Bounded Eric Hughes
  2008-04-21 18:04  4%                                                       ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-21 18:50  5%                                                       ` Dmitry A. Kazakov
  2008-04-22  0:31  6%                                                         ` Ada.Strings.Bounded Eric Hughes
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-21 18:50 UTC (permalink / raw)


On Mon, 21 Apr 2008 09:35:36 -0700 (PDT), Eric Hughes wrote:

> ARM 2.4.1 "Decimal Literals"
> has no length limitation on 'numeral'.

Hmm, I don't see it saying this. Do you mean that the syntax rule specifies
not limit?

If so, we have visited this before, that would not prove your point.
Putting no explicit limit does not require its absence. Consider German
highways, there is no speed limit, alas only at certain places. Should it
mean existence of cars moving faster that light?

It is legal not to compile [some] legal programs.

> On Apr 21, 8:08 am, Robert A Duff <bobd...@shell01.TheWorld.com>

>> Universal_integers can be
>> implicitly converted to various integer types.
> 
> This was the whole point of the discussion--why such implicit
> conversions do not break the type system.  It's not like integers are
> a tagged type.

I don't see any difference, except that the type tag is not stored in (more
precisely, cannot be obtained from) the values.

>> type My_Int is range 1..100;
>> Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
>>                               -- Y is of type My_Int.
> 
> Are there other places in Ada when the context of an operation
> determines the type of the operands of the function and thus also the
> function signature?

The context does not define the types. It resolves overloaded symbols.

> Context-dependent function selection need not break correctness of a
> program, even when there's ambiguity in what function might be
> selected (non-deterministic execution).  The conditions for this to
> work are implicitly present with integer types.  I believe it's
> possible to make them explicit for arbitrary types.

The following program:

with Ada.Text_IO;  use Ada.Text_IO;

procedure Test_Int is
   type My_Int is range 1..100;
   function "+" (L, R : My_Int) return My_Int is
   begin
      return 10;
   end "+";
   Y : constant My_Int := 1 + 1;
begin
   Put_Line (My_Int'Image (Y));
end Test_Int;

illustrates Robert's point. It shall print 10.

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



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-21 16:35  3%                                                     ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-21 18:04  4%                                                       ` Robert A Duff
  2008-04-22  0:19  3%                                                         ` Ada.Strings.Bounded Eric Hughes
  2008-04-21 18:50  5%                                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Robert A Duff @ 2008-04-21 18:04 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 21, 8:08 am, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> Anyway, it might make your point clearer if you explain it again,
>> but using proper Ada terminology this time.
>
> I will endeavor to use Ada terminology when I can, but there is not
> Ada terminology for some of the things I'm talking about.  I'll start
> back at the beginning of the argument I made just previously.  I'm
> stripping this argument down to its basics.  I've removed any piece of
> the argument that includes anything that might be mistaken for an Ada
> arithmetic operation.

OK, thanks.  I think I get it now.

> Eric Hughes <eric....@gmail.com> writes:
>> Every universal_integer has a literal expression 'm'.
>
> Let N0 be the value in {\bb N} for this universal integer.  This N0 is
> not an Ada natural, it's a mathematical one.  I will presume that
> there is an injective map from universal_integer into {\bb Z} that
> preserves value.  I would find it absurd to disagree with this
> premise, but I'd rather make it explicit than not.
>
> What I mean by what I said is that there a sequence of characters 'm'
> that, when used as a static_expression in a number_declaration
> (3.3.2/2), creates an Ada constant whose value is equal to N0.  'm' is
> not an Ada construct, it's a sequence of characters valid for
> substitution into an Ada program.  Furthermore, we can find such an
> 'm' that is valid as a 'numeral' (2.4.1/3), consisting only of
> digits.  Since I was only discussing positive upper bounds and
> 'numeral' has no minus sign in its syntax, this sequence of characters
> is unique and always exists.
>
> Eric Hughes <eric....@gmail.com> writes:
>> The expression 'm+1' is also a literal.
>
> Let N1 = N0 + 1.  N1 is also in {\bb N}. There's another sequence of
> characters, which I called 'm+1', again also valid as an Ada
> 'numeral', that has the value N1.  We compute this using outside-of-
> Ada ordinary mathematical operations.  ARM 2.4.1 "Decimal Literals"
> has no length limitation on 'numeral'.

OK, so m is some sequence of characters -- an integer literal.
That's what I was confused about before.

(Nit: an implementation is allowed to restrict integer literals
to 200 characters.  See RM-2.2(14).  It is not required to do
so, and anyway, it doesn't change the fact that there are an
infinite number of integers.)

> Eric Hughes <eric....@gmail.com> writes:
>> All literals have type universal_integer (see 2.4/3).
>> Therefore 'm+1' is also a universal_integer.
>
> Admittedly I was only talking about integer literals; other literals
> have different types.  The term "integer literal" is defined in ARM
> 2.4/1:
>> an integer literal is a numeric_literal without a point
> Both sequences of characters 'm' and 'm+1' consist only of digits, so
> each is also valid as an "integer literal".
>
> So far I've only dealt with syntactic issues.  I need to now make an
> assertion about type.  From ARM 2.4/3:
>> The type of an integer literal is universal_integer.
>
> I see two arguably-correct ways of interpreting this statement, one
> absolute and one contingent:
> -- Every integer literal has a type and that type is
> universal_integer.
> -- If an integer literal has a type, that type is universal_integer.
> I believe the contingent version is not the meaning.

Yes.  Every integer literal has type univ_int.

>...The ARM
> statement is written in unconditional language.  "The type of an
> integer literal" identifies the unique type associated with that
> integer literal and implies that there is always such a type.  The
> contingent version of this sentence would be "The type of an integer
> literal, if any, is universal_integer."  But that's not what it says.
>
> Hence both 'm' and 'm+1' have a type, and that that type is
> universal_integer.  By induction, universal_integer has no upper
> bound.

Sure.  But I don't see the need for all this song and dance,
since AARM-3.5.4 says:

8     The set of values for a signed integer type is the (infinite) set of
mathematical integers[, though only values of the base range of the type are
fully supported for run-time operations]. The set of values for a modular
integer type are the values from 0 to one less than the modulus, inclusive.

We all know there are an infinite number of integers, so why did
you want to prove it?  Universal_integer is not special in this
regard.  And for compile time (static) calculations, Ada places
no limit on the size of integers.

> On Apr 21, 8:08 am, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> The expression 'm+1' is certainly NOT a literal -- it's a function
>> call, passing an identifier and a literal as the actual parameters.
>
> I redid the argument to get rid of this ambiguity.  Admittedly I had
> not distinguished addition on {\bb N} and addition on Ada types.  My
> argument doesn't rely upon addition on any Ada type.

OK, I see.

But you could rely on integer addition (for static values of type
root_integer, for example).

>> Universal_integers can be
>> implicitly converted to various integer types.
>
> This was the whole point of the discussion--why such implicit
> conversions do not break the type system.  It's not like integers are
> a tagged type.
>
>> type My_Int is range 1..100;
>> Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
>>                               -- Y is of type My_Int.
>
> Are there other places in Ada when the context of an operation
> determines the type of the operands of the function and thus also the
> function signature?

Overload resolution always takes the context into account,
for function calls.  Nothing special about "+" in that regard.
If you say:

    P(Param => F(X));

Then the type of Param helps determine which F is called (if there are
many functions called F that are directly visible).  The type of X also
helps determine which F is called -- and there might be several
overloaded X's.  There might also be several P's, some of which have
a Param.

> Context-dependent function selection need not break correctness of a
> program, even when there's ambiguity in what function might be
> selected (non-deterministic execution). The conditions for this to
> work are implicitly present with integer types.

Seems like "need not break" isn't good enough -- I want to prove that it
"does not break".  There could be a user-defined "+".

>...I believe it's
> possible to make them explicit for arbitrary types.

Hmm.  I guess I need an example to see what you're getting at.
Choosing which function to call nondeterministically seems
like an Obviously Bad Idea, to me, so perhaps I don't understand
what you mean.

- Bob



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-21 14:08  5%                                                   ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-21 16:35  3%                                                     ` Eric Hughes
  2008-04-21 18:04  4%                                                       ` Ada.Strings.Bounded Robert A Duff
  2008-04-21 18:50  5%                                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Eric Hughes @ 2008-04-21 16:35 UTC (permalink / raw)


On Apr 21, 8:08 am, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> Anyway, it might make your point clearer if you explain it again,
> but using proper Ada terminology this time.

I will endeavor to use Ada terminology when I can, but there is not
Ada terminology for some of the things I'm talking about.  I'll start
back at the beginning of the argument I made just previously.  I'm
stripping this argument down to its basics.  I've removed any piece of
the argument that includes anything that might be mistaken for an Ada
arithmetic operation.

Eric Hughes <eric....@gmail.com> writes:
> Every universal_integer has a literal expression 'm'.

Let N0 be the value in {\bb N} for this universal integer.  This N0 is
not an Ada natural, it's a mathematical one.  I will presume that
there is an injective map from universal_integer into {\bb Z} that
preserves value.  I would find it absurd to disagree with this
premise, but I'd rather make it explicit than not.

What I mean by what I said is that there a sequence of characters 'm'
that, when used as a static_expression in a number_declaration
(3.3.2/2), creates an Ada constant whose value is equal to N0.  'm' is
not an Ada construct, it's a sequence of characters valid for
substitution into an Ada program.  Furthermore, we can find such an
'm' that is valid as a 'numeral' (2.4.1/3), consisting only of
digits.  Since I was only discussing positive upper bounds and
'numeral' has no minus sign in its syntax, this sequence of characters
is unique and always exists.

Eric Hughes <eric....@gmail.com> writes:
> The expression 'm+1' is also a literal.

Let N1 = N0 + 1.  N1 is also in {\bb N}. There's another sequence of
characters, which I called 'm+1', again also valid as an Ada
'numeral', that has the value N1.  We compute this using outside-of-
Ada ordinary mathematical operations.  ARM 2.4.1 "Decimal Literals"
has no length limitation on 'numeral'.

Eric Hughes <eric....@gmail.com> writes:
> All literals have type universal_integer (see 2.4/3).
> Therefore 'm+1' is also a universal_integer.

Admittedly I was only talking about integer literals; other literals
have different types.  The term "integer literal" is defined in ARM
2.4/1:
> an integer literal is a numeric_literal without a point
Both sequences of characters 'm' and 'm+1' consist only of digits, so
each is also valid as an "integer literal".

So far I've only dealt with syntactic issues.  I need to now make an
assertion about type.  From ARM 2.4/3:
> The type of an integer literal is universal_integer.

I see two arguably-correct ways of interpreting this statement, one
absolute and one contingent:
-- Every integer literal has a type and that type is
universal_integer.
-- If an integer literal has a type, that type is universal_integer.
I believe the contingent version is not the meaning.  The ARM
statement is written in unconditional language.  "The type of an
integer literal" identifies the unique type associated with that
integer literal and implies that there is always such a type.  The
contingent version of this sentence would be "The type of an integer
literal, if any, is universal_integer."  But that's not what it says.

Hence both 'm' and 'm+1' have a type, and that that type is
universal_integer.  By induction, universal_integer has no upper
bound.


On Apr 21, 8:08 am, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> The expression 'm+1' is certainly NOT a literal -- it's a function
> call, passing an identifier and a literal as the actual parameters.

I redid the argument to get rid of this ambiguity.  Admittedly I had
not distinguished addition on {\bb N} and addition on Ada types.  My
argument doesn't rely upon addition on any Ada type.

> Universal_integers can be
> implicitly converted to various integer types.

This was the whole point of the discussion--why such implicit
conversions do not break the type system.  It's not like integers are
a tagged type.

> type My_Int is range 1..100;
> Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
>                               -- Y is of type My_Int.

Are there other places in Ada when the context of an operation
determines the type of the operands of the function and thus also the
function signature?

Context-dependent function selection need not break correctness of a
program, even when there's ambiguity in what function might be
selected (non-deterministic execution).  The conditions for this to
work are implicitly present with integer types.  I believe it's
possible to make them explicit for arbitrary types.

Eric




^ permalink raw reply	[relevance 3%]

* Re: Ada.Strings.Bounded
  2008-04-21  0:44  5%                                                 ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-21 14:08  5%                                                   ` Robert A Duff
  2008-04-21 16:35  3%                                                     ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Robert A Duff @ 2008-04-21 14:08 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Wed, 16 Apr 2008 07:40:32 -0700 (PDT), Eric Hughes wrote:
>> By my
>> previous proof about universal_integer, the expression 'm+1' is also a
>> universal_integer.
>
> As a reference, that message was
> <b7c7de31-2e96-4f5b-882e-5e991d52ae93@a9g2000prl.googlegroups.com>.
>
> On Apr 16, 12:28 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> How so? Clearly "+" is not closed in Universal_Integer.
>
> No, addition is closed in universal integer.  It's an implication of
> its definition. From 3.5.4/14
>> Integer literals are all of the type universal_integer, the
>> universal type (see 3.4.1) for the class rooted at root_integer,
>> allowing their use with the operations of any integer type.
>
> Every universal_integer has a literal expression 'm'. The expression 'm
> +1' is also a literal.  All literals have type universal_integer (see
> 2.4/3).  Therefore 'm+1' is also a universal_integer.

No, that's not quite right.  There's no such thing as a "literal
expression" in Ada, so I don't know what you mean by that.  Static
expression?  Expression of type universal_integer?  No idea...
The expression 'm+1' is certainly NOT a literal -- it's a function
call, passing an identifier and a literal as the actual parameters.

An integer literal has type universal_integer, as you said, but
universal_integer has no "+" operator.  There is a "+" for root_integer,
and also for user-defined integer types.  Universal_integers can be
implicitly converted to various integer types.

The type of an expression like m+1 depends in part on the context.

M : constant := 123; -- M is of type universal_integer.
X : constant := M + 1; -- The "+" for root_integer is called.
                       -- X is of type universal_integer.

type My_Int is range 1..100;
Y : constant My_Int := 1 + 1; -- The "+" of My_Int is called.
                              -- Y is of type My_Int.

In both of the above "+" calls, the universal_integer operands are
implicitly converted -- to root_integer in the first case, and to My_Int
in the second case.

Static expressions are calculated exactly (arbitrary range).
Dynamic expressions are limited to some implementation
defined ranges -- this includes run-time values of type
root_integer and universal_integer.

> I should have realized that this was the point of the agreement long
> before.  The ARM is wrong on this point, or at the very least
> inconsistent.  Either they'll have to just say it's not a type (that
> is, an implementable Ada type) or they'll have to change the rules
> about integer literals.  The above proof about 'm+1' can be taken as a
> proof of inconsistency, if you like.

I don't see any inconsistency here.  An inconsistency would be a case
where the RM contradicts itself about whether a certain program is
legal, or what the run-time semantics of the program is.  You have
proven nothing of the kind, as far as I can see.

Anyway, it might make your point clearer if you explain it again,
but using proper Ada terminology this time.  I'd be interesting
in understanding your point...

- Bob



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-16 18:28  5%                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-21  0:44  5%                                                 ` Eric Hughes
  2008-04-21 14:08  5%                                                   ` Ada.Strings.Bounded Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-21  0:44 UTC (permalink / raw)


On Wed, 16 Apr 2008 07:40:32 -0700 (PDT), Eric Hughes wrote:
> By my
> previous proof about universal_integer, the expression 'm+1' is also a
> universal_integer.

As a reference, that message was
<b7c7de31-2e96-4f5b-882e-5e991d52ae93@a9g2000prl.googlegroups.com>.

On Apr 16, 12:28 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> How so? Clearly "+" is not closed in Universal_Integer.

No, addition is closed in universal integer.  It's an implication of
its definition. From 3.5.4/14
> Integer literals are all of the type universal_integer, the
> universal type (see 3.4.1) for the class rooted at root_integer,
> allowing their use with the operations of any integer type.

Every universal_integer has a literal expression 'm'. The expression 'm
+1' is also a literal.  All literals have type universal_integer (see
2.4/3).  Therefore 'm+1' is also a universal_integer.

The same kind argument works to argue to prove closure, although that
requires recursion on the structure of 'm'.  Writing up that proof
would be beside the point right now.

> Universal_Integer is a type, merely because ARM tells so.

I should have realized that this was the point of the agreement long
before.  The ARM is wrong on this point, or at the very least
inconsistent.  Either they'll have to just say it's not a type (that
is, an implementable Ada type) or they'll have to change the rules
about integer literals.  The above proof about 'm+1' can be taken as a
proof of inconsistency, if you like.

My attitude is that you can't declare a variable of universal_integer,
so it's no great harm if it's not an ordinary Ada type.  There's
another point I might have made earlier: universal_integer is a type
that could well appear in other programming languages, because it's a
completely abstract type, and I do not mean "abstract" in any of the
ways that's used as a reserved word in any programming language.  By
"completely abstract", I mean it's a pure concept of thought, a
mathematical abstraction.

It's the connection of such mathematically abstract types to
programming language types that was the point of contact with the
original posting.

Eric



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-16 14:40  3%                                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-16 18:28  5%                                               ` Dmitry A. Kazakov
  2008-04-21  0:44  5%                                                 ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-16 18:28 UTC (permalink / raw)


On Wed, 16 Apr 2008 07:40:32 -0700 (PDT), Eric Hughes wrote:

> By my
> previous proof about universal_integer, the expression 'm+1' is also a
> universal_integer.

How so? Clearly "+" is not closed in Universal_Integer. For any compiler,
there always exists an Ada program such that:

   M : constant := <some-literal>; -- Compiles
   N : constant := M + 1;  -- Does not compile

[...]
> By assumption, every universal_integer that appears in that program is
> a member of Large_Enough_Integer.

No. It does not include Universal_Integer, Root_Integer and BigNum if the
latter two will ever come. Certainly any of these types (should they become
named) would have either no attribute S'Range defined, or else one raising
Constraint_Error.

> For a compiled program with an internally limited compiler, then, we
> have the following sketch of potential type relationships:
>     supremum_compilable_integer --> supremum_integer_for_program_P -->
> root_integer
> I didn't put universal_integer in there, though, because it's not a
> type in the same sense that these others are.

Universal_Integer is a type, merely because ARM tells so. As I said before
it is not what you hold it for. Further, you cannot have what you want,
because that would be incomputable.

> A compiler, in theory (though certainly not in present practice), is
> capable of generating expressions for arbitrarily large integers.

Any compiler is a program with a finite number of states. Let each state of
it compiles a legal Ada program (in reality the ratio is much lower than
that). Now consider the following set of programs Foo_n:

procedure Foo_n is
   N : constant := <decimal-literal-of-n>;
begin
   null;
end Foo_n;

Clearly, this set is larger that the set of all states. Therefore, there
exists m, such that Foo_m is not compilable. q.e.d.

[Surely, you could design an Ada compiler which would compile one given
legal Ada program. But you cannot have a compiler which would compile any
legal program.]

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



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-16  8:16  6%                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-16 14:40  3%                                             ` Eric Hughes
  2008-04-16 18:28  5%                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-16 14:40 UTC (permalink / raw)


On Apr 16, 2:16 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Universal_Integer is merely an integer type.

OK, now you're just wrong.  Wrong, that is, assuming that by "integer
type" you mean an "integer type as defined by Ada" and not some other
notion of "integer type".  I've never seen you to acknowledge any
other kind of type here, so I believe I'm making that assumption in
good faith.

Suppose there existed some single and specific Ada integer type M
which is the same type as universal_integer.  All non-modular integer
types are defined by ranges (see 3.5.4 "Integer Types").  Since M is a
scalar type, the lower bound is M'First and the upper bound is M'Last
(see 3.5).  Since M is an integer type, it is declarable.  Let 'm' be
an integer literal by which the upper bound of M can be declared.  By
the premise, 'm' is an expression of universal_integer.  By my
previous proof about universal_integer, the expression 'm+1' is also a
universal_integer.  But 'm+1' is not a member of M.  Thus M cannot be
a type for universal_integer.

Now you'll come right back and cite things that aren't in the language
specification: specific compilers and specific programs.  Were you to
insist upon citing these, it would be tantamount to saying the
standard isn't actually normative, that instead practice is
normative.  But then I'd believe that you don't know the meaning of
the word "normative".

But I'll address them anyway, to forestall confusion.

Let's start with programs.  Take a the entire source code of any
program.  It's finite.  For that body of code, there's a
universal_integer expression of greatest absolute value.  Call it
'n'.  Declare the type
    type Large_Enough_Integer is range -n .. n ;
By assumption, every universal_integer that appears in that program is
a member of Large_Enough_Integer.  Furthermore, every integer type has
bounds that are members of Large_Enough_Integer.  Thus every integer
value that could ever be in that program has a value that's a member
of Large_Enough_Integer.  But Large_Enough_Integer is not the same as
universal_integer, because the value of 'n+1' is not in
Large_Enough_Integer and it is in universal_integer.  Thus, what's
true is the following predicate:
   For every program P,
   there exists an integer type N,
   for all executions E of P,
   for all times T within E,
   for all variables X within P,
   the value of X at time T within E is a value of N.

This predicate does not make N into universal_integer.  What it says
is that there's a relativized version of universal_integer which is
just barely adequate for every program.  But universal_integer is NOT
defined on a program-by-program basis.  It's defined for the language
as a whole.  For each program, there's a large-enough type, but that
type is not universal_integer.  It's supremum_integer_for_program_P.

The case for compilers is rather more subtle.  Let's dispose of the
easy case first.  Suppose there's some internal limit on the size of
integer types that a compiler accepts; call the type at that limit
'supremum_compilable_integer'.  Then that compiler does not accept
programs P where supremum_integer_for_program_P won't fit into
supremum_compilable_integer.  Now 'supremum_compilable_integer+1' is
also a universal_integer, but one that this compiler does not accept.
Now there's no requirement that a compiler be able to handle every
universal_integer in order to be a conformant compiler.  Such a
requirement would be impossible to satisfy, because it would require
an execution size that was unbounded, even though the compiler itself
could be bounded.  Hence for this case too, there's a relativized
version of universal_integer that applies to the compiler, but that
type isn't universal_integer either.

For a compiled program with an internally limited compiler, then, we
have the following sketch of potential type relationships:
    supremum_compilable_integer --> supremum_integer_for_program_P -->
root_integer
I didn't put universal_integer in there, though, because it's not a
type in the same sense that these others are.

A compiler, in theory (though certainly not in present practice), is
capable of generating expressions for arbitrarily large integers.
I'll be willing to discuss this case later, after the simpler cases
are properly disposed of.

Eric



^ permalink raw reply	[relevance 3%]

* Re: Ada.Strings.Bounded
  2008-04-16  2:46  6%                                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-16  8:16  6%                                           ` Dmitry A. Kazakov
  2008-04-16 14:40  3%                                             ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-16  8:16 UTC (permalink / raw)


On Tue, 15 Apr 2008 19:46:12 -0700 (PDT), Eric Hughes wrote:

> On Tue, 15 Apr 2008 06:56:57 -0700 (PDT), Eric Hughes wrote:
>> I assert that that Ada as currently defined has no bound on the size
>> of numbers within universal_integer.
> 
> On Apr 15, 8:58 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> It specifies the lower bound and leaves the upper bound up to the vendor.
>> Which by no means imply that there were no upper bound.
> 
> That's an upper bound for a compiler, not for "Ada as currently
> defined".  Please check my language carefully.
> 
>> Moreover,
>> because the number of all instances of all existed, existing and future Ada
>> compilers is obviously finite, there also exists the upper bound of
>> universal_integer as a whole.
> 
> "All compilers that were, all that are, and all that will ever be"--
> these are not part of the Ada language definition.  My assertion
> stands.

Neither a bound nor its absence is required. The former does not imply the
latter. Try a certified Ada compiler on:

   X : constant := 2**(2**(2**(2**(2**1000))));

> I would still like to know what you think universal_integer actually is.

Universal_Integer is merely an integer type.

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-16  2:51  6%                                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-16  8:00  6%                                           ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-16  8:00 UTC (permalink / raw)


On Tue, 15 Apr 2008 19:51:17 -0700 (PDT), Eric Hughes wrote:

> On Tue, 15 Apr 2008 07:20:15 -0700 (PDT), Eric Hughes wrote:
>> Perhaps you could explain what you want universal_integer to be.
> 
> On Apr 15, 9:23 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> Merely the type of a static numeric expression. Well, it isn't, a
>> counterexample is:
>>
>>    A'Length  (ARM 3.6.2)
> 
> The fact that lengths are limited does not mean that their values
> cannot sit within a type whose values are not.  The set of possible
> values of lengths for a certain compiler are a subset of the values of
> universal_integer.

A'Length is of Universal_Integer.

>> Universal_Integer is not necessarily Root_Integer, but somewhere close to
>> the root of Root_Integer'Class.
> 
> "Somewhere close" is not a definition.  Please be more specific.

It is specific. "Close" means: a small tree distance to Root_Integer. (Tree
is the type inheritance tree.)

>>> If you can show me a Ada definition that can store a
>>> universal_integer, only then will I believe you that it's the kind of
>>> type that's just like an ordinary Ada type.
>>
>>    type T is abstract private;
>>
>> Can you store T?
> 
> By ordinary type, I mean the kind that's assignable, not abstract, not
> an interface, something you can declare a variable of.

So, actually, the whole point is that we could not have a variable of
Universal_Integer?

It is not uncommon. I cannot have a variable of a constant Boolean.

   X : constant Boolean := False;
begin
   X := True; -- Illegal, "constant" disallows ":="

Maybe it is indefinite types which worry you? Yes, I cannot have a variable
of String:

   X : String; -- Illegal, no constraint given

There is nothing special in Universal_Integer except that it lacks some
"primitive" operations, an Integer possess.

The only really interesting property of Universal_Integer is that its
constants are required to be static. I would allow such constraints for any
types, in order to introduce static compilation units (functions, packages,
maybe, procedures).

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15 20:33  6%                           ` Ada.Strings.Bounded Georg Bauhaus
@ 2008-04-16  3:11  6%                             ` Eric Hughes
  0 siblings, 0 replies; 200+ results
From: Eric Hughes @ 2008-04-16  3:11 UTC (permalink / raw)


Eric Hughes wrote:
> This is where that Hoare
> paper that I mentioned a while back, "Proof of correctness of data
> representations" comes in.  It describes exactly how this works.

On Apr 15, 2:33 pm, Georg Bauhaus <rm.tsoh.plus-
bug.bauh...@maps.futureapps.de> wrote:
> Thanks for the title. I see that some methods are actually
> heading in this direction. Hopefully, the basic idea that
> data and timing must be formally correct, too, finds its way
> into education.

You're welcome.  That essay is collected in the book _Essays in
Computing Science_.

The title of that essay might well have been titled "Proof of
correctness of compiler output", but Hoare doesn't go into compilation
issues as such in enough depth to justify such a title.  You'd have a
program annotated with some properties and their proof, a compiler
that converted the proof to one in its execution model, and proof-
carrying object code as its output.  Even if the proof annotations of
the program were empty (as today), you can still infer some basic
semantics from expressions and statements by themselves and generate
checkable proof.  I suspect that discipline would get rid of a lot of
code generation defects.

Eric




^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15 15:23  6%                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-16  2:51  6%                                         ` Eric Hughes
  2008-04-16  8:00  6%                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-16  2:51 UTC (permalink / raw)


On Tue, 15 Apr 2008 07:20:15 -0700 (PDT), Eric Hughes wrote:
> Perhaps you could explain what you want universal_integer to be.

On Apr 15, 9:23 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Merely the type of a static numeric expression. Well, it isn't, a
> counterexample is:
>
>    A'Length  (ARM 3.6.2)

The fact that lengths are limited does not mean that their values
cannot sit within a type whose values are not.  The set of possible
values of lengths for a certain compiler are a subset of the values of
universal_integer.

> Universal_Integer is not necessarily Root_Integer, but somewhere close to
> the root of Root_Integer'Class.

"Somewhere close" is not a definition.  Please be more specific.

> > If you can show me a Ada definition that can store a
> > universal_integer, only then will I believe you that it's the kind of
> > type that's just like an ordinary Ada type.
>
>    type T is abstract private;
>
> Can you store T?

By ordinary type, I mean the kind that's assignable, not abstract, not
an interface, something you can declare a variable of.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15 14:58  6%                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-16  2:46  6%                                         ` Eric Hughes
  2008-04-16  8:16  6%                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-16  2:46 UTC (permalink / raw)


On Tue, 15 Apr 2008 06:56:57 -0700 (PDT), Eric Hughes wrote:
> I assert that that Ada as currently defined has no bound on the size
> of numbers within universal_integer.

On Apr 15, 8:58 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> It specifies the lower bound and leaves the upper bound up to the vendor.
> Which by no means imply that there were no upper bound.

That's an upper bound for a compiler, not for "Ada as currently
defined".  Please check my language carefully.

> Moreover,
> because the number of all instances of all existed, existing and future Ada
> compilers is obviously finite, there also exists the upper bound of
> universal_integer as a whole.

"All compilers that were, all that are, and all that will ever be"--
these are not part of the Ada language definition.  My assertion
stands.

I would still like to know what you think universal_integer actually
is.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15  1:35  4%                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-15 20:33  6%                           ` Georg Bauhaus
  2008-04-16  3:11  6%                             ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Georg Bauhaus @ 2008-04-15 20:33 UTC (permalink / raw)


Eric Hughes wrote:

> Finally, in order for this to work, you have to be able to connect
> execution of the high-level program with execution of a program of
> equivalent effect in the execution model.  This is where that Hoare
> paper that I mentioned a while back, "Proof of correctness of data
> representations" comes in.  It describes exactly how this works.

Thanks for the title. I see that some methods are actually
heading in this direction. Hopefully, the basic idea that
data and timing must be formally correct, too, finds its way
into education.



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15 14:20  5%                                     ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-15 15:23  6%                                       ` Dmitry A. Kazakov
  2008-04-16  2:51  6%                                         ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-15 15:23 UTC (permalink / raw)


On Tue, 15 Apr 2008 07:20:15 -0700 (PDT), Eric Hughes wrote:

> Perhaps you could explain what you want universal_integer to be.

Merely the type of a static numeric expression. Well, it isn't, a
counterexample is:

   A'Length  (ARM 3.6.2)

Universal_Integer is not necessarily Root_Integer, but somewhere close to
the root of Root_Integer'Class.

> If you can show me a Ada definition that can store a
> universal_integer, only then will I believe you that it's the kind of
> type that's just like an ordinary Ada type.

   type T is abstract private;

Can you store T?

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
       [not found]                                         ` <bc3a8b4e-63fe-47a6-b10b-7056f6d7d586@w5g2000prd.googlegroups.com>
@ 2008-04-15 14:58  6%                                       ` Dmitry A. Kazakov
  2008-04-16  2:46  6%                                         ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-15 14:58 UTC (permalink / raw)


On Tue, 15 Apr 2008 06:56:57 -0700 (PDT), Eric Hughes wrote:

> On Mon, 14 Apr 2008 19:07:25 -0700 (PDT), Eric Hughes wrote:
>> Seriously, we just disagree about this.  I can't take
>> universal_integer seriously as a root class, because it's impossible
>> to write down any representation of it.
> 
> On Apr 15, 2:02 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> Yes, because it is not what you wanted it be.
> 
> I assert that that Ada as currently defined has no bound on the size
> of numbers within universal_integer.

It specifies the lower bound and leaves the upper bound up to the vendor.
Which by no means imply that there were no upper bound. In any given
instance of Ada compiler universal_integer has an upper bound. Moreover,
because the number of all instances of all existed, existing and future Ada
compilers is obviously finite, there also exists the upper bound of
universal_integer as a whole.

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-15  8:02  6%                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-15 14:20  5%                                     ` Eric Hughes
  2008-04-15 15:23  6%                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
       [not found]                                         ` <bc3a8b4e-63fe-47a6-b10b-7056f6d7d586@w5g2000prd.googlegroups.com>
  1 sibling, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-15 14:20 UTC (permalink / raw)


On Mon, 14 Apr 2008 19:07:25 -0700 (PDT), Eric Hughes wrote:
> Seriously, we just disagree about this.  I can't take
> universal_integer seriously as a root class, because it's impossible
> to write down any representation of it.

On Apr 15, 2:02 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Yes, because it is not what you wanted it be.

My belief about universal_integer is rooted in the language
definition.  I assert that that Ada as currently defined has no bound
on the size of numbers within universal_integer.  Here is my argument.

The best definition is in ARM 3.4.1(6/2-7).  (Defect report: this
doesn't appear in the index entry for universal_integer.)  Wherein:

> The set of values of a universal type is the undiscriminated
> union of the set of values possible for any definable type
> in the associated class.

The associated class to universal_integer is the signed integer type
(3.5.4), delineated by ranges given by static simple_expression.
There's no length limitation on an expression in the language, so
arbitrarily large ranges are possible.  Thus I can define the
following series of types:
    type I1 is range -2^10 .. 2^10 ;
    type I2 is range -2^100 .. 2^100 ;
    type I3 is range -2^1000 .. 2^1000 ;
    -- ...
The exponent in I(n) is an integer within the range of I(n-1).  The
type of an integer literal is universal_integer (2.4), which means
that if I(n-1) is well-defined, then so is I(n).  (Hence the
requirement for bignum arithmetic in the compiler.)  If you want to
exhibit a bound on universal_integer as a counterexample, I will take
its logarithm, round up, and add 1, and use that index to exhibit a
type definition that exceeds this bound.  Every integer is thus a
member of universal_integer.

If you can show me a Ada definition that can store a
universal_integer, only then will I believe you that it's the kind of
type that's just like an ordinary Ada type.

Perhaps you could explain what you want universal_integer to be.

Eric



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-15  2:07  4%                                 ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-15  8:02  6%                                   ` Dmitry A. Kazakov
  2008-04-15 14:20  5%                                     ` Ada.Strings.Bounded Eric Hughes
       [not found]                                         ` <bc3a8b4e-63fe-47a6-b10b-7056f6d7d586@w5g2000prd.googlegroups.com>
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-15  8:02 UTC (permalink / raw)


On Mon, 14 Apr 2008 19:07:25 -0700 (PDT), Eric Hughes wrote:

> On Apr 14, 12:52 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> I think it is wrong to consider N and universal_integer equivalent.
> 
> Sure.  It's {\bb Z} and universal_integer that are equivalent.
> 
> Seriously, we just disagree about this.  I can't take
> universal_integer seriously as a root class, because it's impossible
> to write down any representation of it.

Yes, because it is not what you wanted it be.

>> Subseting is not a sufficient condition for a
>> successful modeling.
> 
> In a discussion that's got a lot of formal logic in it, the word
> "model" already means something pretty specific, usually involving a
> Tarski structure.

That is beside the point. A subset of values is not yet a type. The
requirement to be a subset (of values) alone does not enforce anything
useful.

>> Actually it is the opposite, a perfect subset cannot
>> be a good model.
> 
> There was paper from the fifties (sorry, no reference handy), which
> used Turing machines to compute a Dedekind cut.  On input a rational
> number, it returned one of the two symbols "<=x" or ">=x".  (You
> cannot compute exact trichotomy without solving the halting problem.)
> In any language describing these machines, there's a least one (Kleene
> minimization), so there's a unique representative of such a machine
> for every computable real number, which means there's a subset
> bijection.  Addition, multiplication, and their inverses are defined
> in terms of the underlying operand-machine (it's pretty easy coding,
> actually).  So there's pretty close to a perfect model of the real
> numbers, whose only real limitation is that run times are horrendously
> slow.  But it's also completely exact, with no compromises but
> execution speed and representation size of a machine.
> 
> The subset is every real number that's computable.  About as good as
> you can do with computers, I'd say.

No. It cannot represent pi and e. Now consider the following:

   type A_Subset_Of_R is (pi, e);  -- Ready!

The above is a perfect subset of R containing both pi and e. Isn't it good?

>> The best models of R aren't even close to subsets. For
>> example intervals with rational bounds.
> 
> In the precise meaning of model, it's just not a model, because
> there's no total ordering on such intervals, so the ordering axioms
> are not satisfied.  In an imprecise meaning, it's real numbers plus
> some other concept, which is more than {\bb R}.

For any model there are properties which are not satisfied. Intervals are
good because they preserve *interesting* properties and provide fair
approximations for properties lost. Total ordering is mere a property,
which has a minor importance to numeric computations. In fact, each second
handbook on numeric methods starts with something like "never ever compare
reals."

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14 18:52  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-15  2:07  4%                                 ` Eric Hughes
  2008-04-15  8:02  6%                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-15  2:07 UTC (permalink / raw)


On Apr 14, 12:52 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> I think it is wrong to consider N and universal_integer equivalent.

Sure.  It's {\bb Z} and universal_integer that are equivalent.

Seriously, we just disagree about this.  I can't take
universal_integer seriously as a root class, because it's impossible
to write down any representation of it.  I believe the approach I've
been thinking about could provide some reasonably solid grounding for
what universal integer is.

> Subseting is not a sufficient condition for a
> successful modeling.

In a discussion that's got a lot of formal logic in it, the word
"model" already means something pretty specific, usually involving a
Tarski structure.  On the other hand, the informal use of the word
"model", in this context, is basically beside the point, which is to
get a precise definition of a hypothetical universal real type,
amongst others.  There are plenty of useful things that are not-quite-
real numbers, such as the one- and two-point compactifications of the
real line, but these are the same thing as real numbers.  If you want
them, fine; just don't try to claim that they are same thing and use a
confusing name for them.

> Actually it is the opposite, a perfect subset cannot
> be a good model.

There was paper from the fifties (sorry, no reference handy), which
used Turing machines to compute a Dedekind cut.  On input a rational
number, it returned one of the two symbols "<=x" or ">=x".  (You
cannot compute exact trichotomy without solving the halting problem.)
In any language describing these machines, there's a least one (Kleene
minimization), so there's a unique representative of such a machine
for every computable real number, which means there's a subset
bijection.  Addition, multiplication, and their inverses are defined
in terms of the underlying operand-machine (it's pretty easy coding,
actually).  So there's pretty close to a perfect model of the real
numbers, whose only real limitation is that run times are horrendously
slow.  But it's also completely exact, with no compromises but
execution speed and representation size of a machine.

The subset is every real number that's computable.  About as good as
you can do with computers, I'd say.

> The best models of R aren't even close to subsets. For
> example intervals with rational bounds.

In the precise meaning of model, it's just not a model, because
there's no total ordering on such intervals, so the ordering axioms
are not satisfied.  In an imprecise meaning, it's real numbers plus
some other concept, which is more than {\bb R}.

Eric



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-14 18:36  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-15  1:39  6%                                 ` Eric Hughes
  0 siblings, 0 replies; 200+ results
From: Eric Hughes @ 2008-04-15  1:39 UTC (permalink / raw)


On Apr 14, 12:36 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> Certainly, but I don't see why should we care about an non-implemented
> type.

Because they make better tools of thought.  Assuming a prospective "-
oid" morphism, universal types provide one half of a type
description.  Representation issues, such as number of bits in an
integer, become an orthogonal issue.  Separation of concerns is
something Ada got right uniquely among programming languages, but
there remain other kinds of concerns yet to separate.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14 18:13  6%                       ` Ada.Strings.Bounded Georg Bauhaus
@ 2008-04-15  1:35  4%                         ` Eric Hughes
  2008-04-15 20:33  6%                           ` Ada.Strings.Bounded Georg Bauhaus
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-15  1:35 UTC (permalink / raw)


On Apr 14, 12:13 pm, Georg Bauhaus <rm.tsoh.plus-
bug.bauh...@maps.futureapps.de> wrote:
> It might be worth noting that this kind of "correctness"
> specifically precludes factors that are essential to typical
> Ada programming: for a program to solve a problem correctly,
> use of time and storage must stay within specified bounds, too.
>
> Is there a definition of "correctness" that includes more than
> the necessary, static, computer agnostic precondition
> of "left side of equation equals right side of equation" no
> matter when and how?

Yes.

To me, the quickest way of getting at the essence of such conditions
is to start trying to write them down.  You need symbols for that.
You need a function symbol for, say, the time something takes and
another for the space something takes.  You need units of time and
units of space for the results.  You need literal expressions for
durations of time and amounts of space to write down bounds.  All
these are analytical symbols that need not be part of the language
they are analyzing.

The traditional method of correctness uses only the symbols of a
programming language combined with those of predicate calculus.
Simply from lack of expressibility, this traditional method cannot
directly address issues of time and space.  You need to obtain those
symbols from somewhere, and this pretty much means constructing an
execution model that provides a place to root those symbols.
Execution models, however, are properties of the target processor and
execution environment, and thus outside of and, really, independent of
the abstractions of high-level languages.  So, to ground this in Ada,
should there be a Ada-wide execution model?  Probably not.  Might
there be someday a way of expressing an execution model in Ada?  I
would hope so.

One of the consequences of this is that, in general, you can't prove
performance predicates about a program by itself, but only together
with an execution model.  Admittedly most execution models are
similar, but it would be a error of categories to assert a universal
one. (I don't mean to say that a canonical one might not be useful.)
There's a whole area of practical experience to gather about the
similarities of such proof prior to standardization, and I wouldn't
rush in quickly.

Finally, in order for this to work, you have to be able to connect
execution of the high-level program with execution of a program of
equivalent effect in the execution model.  This is where that Hoare
paper that I mentioned a while back, "Proof of correctness of data
representations" comes in.  It describes exactly how this works.

Eric



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-14 15:50  5%                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-14 18:52  6%                               ` Dmitry A. Kazakov
  2008-04-15  2:07  4%                                 ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-14 18:52 UTC (permalink / raw)


On Mon, 14 Apr 2008 08:50:21 -0700 (PDT), Eric Hughes wrote:

> On Apr 14, 3:07 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> If you are aiming at Liskov substitutability
>> principle,
> 
> But I'm not aiming for that.  It's related, to be sure, but it's not
> the same.  If you don't acknowledge that a universal type is a
> different creature than an ordinary type, then you would have to see
> only preexisting relationships.

I think it is wrong to consider N and universal_integer equivalent.

>>> So I can now outline what the relationship ought to be:
>>> -- The set of values of an implemented type is
>>>       a _subset_ of the terms of the universal type.
>>
>> Counterexample: NaN of Float.
> 
> I take from what you're saying that the ordinary way of bringing
> floating point arithmetic into a language is not an implementation of
> universal Real numbers.  That's true.

It is not a subset of R. Subseting is not a sufficient condition for a
successful modeling. Actually it is the opposite, a perfect subset cannot
be a good model. The best models of R aren't even close to subsets. For
example intervals with rational bounds.

>> The set of values of a derived type is neither subset or superset. It is a
>> different set.
> 
> If you insist, but this is not derivation.

It makes life a lot easier. Otherwise you will need to introduce encodings,
have to define the underlying bit patterns, and will never be able to
abstract implementations.
 
>>> -- The set of operators on an implemented type
>>>       _satisfy_ the axioms of the universal type.
>>
>> This cannot work because any implementation is necessarily a DFA.
> 
> ???

Programs are DFA (except hardware interrupts etc).

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14 15:25  6%                             ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-14 18:36  6%                               ` Dmitry A. Kazakov
  2008-04-15  1:39  6%                                 ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-14 18:36 UTC (permalink / raw)


On Mon, 14 Apr 2008 08:25:41 -0700 (PDT), Eric Hughes wrote:

> On Apr 14, 2:00 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:

>> There is a difference between types and their constrained subtypes in terms
>> of substitutability. That's why the language has Constraint_Error defined.
>> The contracts extended by Constraint_Error aren't violated and everything
>> is fine.
> 
> Sure, but again not the point.  The relationship between a universal
> type and an implemented type is NOT the same as that between two
> implemented types.

Certainly, but I don't see why should we care about an non-implemented
type. Well, an application dealing with mathematical objects might be
interesting in modeling N, but it is not the language concern. The same way
as Ada does not care about types of organic molecules...

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14 16:09  6%                     ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-14 18:13  6%                       ` Georg Bauhaus
  2008-04-15  1:35  4%                         ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Georg Bauhaus @ 2008-04-14 18:13 UTC (permalink / raw)


Eric Hughes wrote:
> On Apr 14, 9:11 am, Adam Beneschan <a...@irvine.com> wrote:
>> Ooops, I must have stumbled into some other newsgroup---I thought I
>> was in comp.lang.ada.
> 
> I did say "heresy".  But the whole point of that discussion was to
> characterize when non-determinism would not break correctness.

It might be worth noting that this kind of "correctness"
specifically precludes factors that are essential to typical
Ada programming: for a program to solve a problem correctly,
use of time and storage must stay within specified bounds, too.

Is there a definition of "correctness" that includes more than
the necessary, static, computer agnostic precondition
of "left side of equation equals right side of equation" no
matter when and how?



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14 15:11  6%                   ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-14 16:09  6%                     ` Eric Hughes
  2008-04-14 18:13  6%                       ` Ada.Strings.Bounded Georg Bauhaus
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-14 16:09 UTC (permalink / raw)


On Apr 14, 9:11 am, Adam Beneschan <a...@irvine.com> wrote:
> Ooops, I must have stumbled into some other newsgroup---I thought I
> was in comp.lang.ada.

I did say "heresy".  But the whole point of that discussion was to
characterize when non-determinism would not break correctness.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-14  9:07  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-14 15:50  5%                             ` Eric Hughes
  2008-04-14 18:52  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-14 15:50 UTC (permalink / raw)


On Apr 14, 3:07 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> If you are aiming at Liskov substitutability
> principle,

But I'm not aiming for that.  It's related, to be sure, but it's not
the same.  If you don't acknowledge that a universal type is a
different creature than an ordinary type, then you would have to see
only preexisting relationships.

> > So I can now outline what the relationship ought to be:
> > -- The set of values of an implemented type is
> >       a _subset_ of the terms of the universal type.
>
> Counterexample: NaN of Float.

I take from what you're saying that the ordinary way of bringing
floating point arithmetic into a language is not an implementation of
universal Real numbers.  That's true.

We can talk about optimal encodings and less-than-optimal encodings,
if you'd like, but I really don't see how the exceptional values of
floating point numbers violate the spirit of the rule.  NaN, but even
more so overflow and underflow, even though they're defined for
hardware implementations, could well be forbidden as accessible values
from within the language.  You clearly couldn't eliminate this kind of
type from ordinary use soon, because it's well-embedded in practice
and skills.

The issue then becomes whether it would be beneficial to also have a
Real-implementing type in the pattern I've mentioned.  The differences
would be small.  Since a calculation that results in an exceptional
value raises an exception, such a value that would otherwise be
assigned is simply not assigned (or even made visible).  I think that
takes care of all the modification that would be needed.

> The set of values of a derived type is neither subset or superset. It is a
> different set.

If you insist, but this is not derivation.

> > -- The set of operators on an implemented type
> >       _satisfy_ the axioms of the universal type.
>
> This cannot work because any implementation is necessarily a DFA.

???

Eric



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-14  8:00  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-14 15:25  6%                             ` Eric Hughes
  2008-04-14 18:36  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-14 15:25 UTC (permalink / raw)


On Apr 14, 2:00 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> If we had universal_string, it would have no assignment anyway, because all
> universal objects are immutable.

Sure, because you can't declare a variable of a universal type.  But
this critique misses the point, which is about the relationship of
types that partially implement a universal type.

> There is a difference between types and their constrained subtypes in terms
> of substitutability. That's why the language has Constraint_Error defined.
> The contracts extended by Constraint_Error aren't violated and everything
> is fine.

Sure, but again not the point.  The relationship between a universal
type and an implemented type is NOT the same as that between two
implemented types.

Eric



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
  2008-04-12 19:46  5%                   ` Ada.Strings.Bounded Georg Bauhaus
  2008-04-12 21:09  5%                   ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-14 15:11  6%                   ` Adam Beneschan
  2008-04-14 16:09  6%                     ` Ada.Strings.Bounded Eric Hughes
  2 siblings, 1 reply; 200+ results
From: Adam Beneschan @ 2008-04-14 15:11 UTC (permalink / raw)


On Apr 12, 11:50 am, Eric Hughes <eric....@gmail.com> wrote:
> On Apr 5, 3:43 am, Pascal Obry <pas...@obry.net> wrote:
>
> >     What to do if we have Put_Line defined for String and
> >     Unbounded_String? Which version gets called?
>
> I know this answer is a bit heretical, but the answer I'd pick is
> "either one".  Non-deterministic execution, if you'd like the
> technical term.

Ooops, I must have stumbled into some other newsgroup---I thought I
was in comp.lang.ada.

                               -- Adam



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-13 23:20  2%                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-14  9:07  6%                           ` Dmitry A. Kazakov
  2008-04-14 15:50  5%                             ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-14  9:07 UTC (permalink / raw)


On Sun, 13 Apr 2008 16:20:24 -0700 (PDT), Eric Hughes wrote:

> Why
> shouldn't you derive from a universal type?  Because it's not
> implementable!

One does not imply another. If you are aiming at Liskov substitutability
principle, you should also remember how it is defined. It is in terms of
*provable* propositions. Pragmatically, the program is correct even if
there exist unreachable states where it could crash. However, LSP does not
work anyway.

> So I can now outline what the relationship ought to be:
> -- The set of values of an implemented type is
>       a _subset_ of the terms of the universal type.

Counterexample: NaN of Float.

(The set of values of a derived type is neither subset or superset. It is a
different set. There could be mappings defined between these two sets in
order to achieve substitutability. Such mappings could be injective, or
not)

> -- The set of operators on an implemented type
>       _satisfy_ the axioms of the universal type.

This cannot work because any implementation is necessarily a DFA.

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-13 23:52  4%                         ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-14  8:00  6%                           ` Dmitry A. Kazakov
  2008-04-14 15:25  6%                             ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-14  8:00 UTC (permalink / raw)


On Sun, 13 Apr 2008 16:52:00 -0700 (PDT), Eric Hughes wrote:

> Speaking formally, which I was trying to do (but failing in the
> details), almost-a-string is a subset of not-a-string.  Axiom
> satisfaction has sharp boundaries that don't usually coincide with
> ordinary conceptual boundaries.  Informally, sure, they're both
> strings.  But the Ada String type, with its padding, does not satisfy
> the axioms of universal_string.  The problem is that it's a fixed
> array, not a fixed array allocation with a variable length like
> Bounded_String.  If I assign the value "A", a String of length 1, to a
> String(2), the length of its value as a universal_string changes from
> 1 to 2.  So even simple assignment violates the axioms.

If we had universal_string, it would have no assignment anyway, because all
universal objects are immutable.

There is a difference between types and their constrained subtypes in terms
of substitutability. That's why the language has Constraint_Error defined.
The contracts extended by Constraint_Error aren't violated and everything
is fine.

> The problem that was the nexus of the original discussion is that
> string literals are of type String and not deemed elements of
> universal_string.

I don't see any harm here. You cannot assign literals.

BTW, there are funny language rules which prevent things like this:

   type Integer is range -5..5;  -- On some tiny machine

   L : constant := ("abcd" & "defg"  & "defg")'Length / 3;
       -- Illegal anyway

So you cannot exploit the limitation of the string index being Positive in
order to construct strings longer than the index at compile time.

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-13 20:10  6%                       ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-13 23:52  4%                         ` Eric Hughes
  2008-04-14  8:00  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-13 23:52 UTC (permalink / raw)


On Apr 13, 2:10 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> There is no such thing as Ada.Strings.String.  I thought maybe you meant
> the package Ada.Strings.Fixed, but that package has no type.  It uses
> the predefined type String (which is declared in Standard, and
> therefore visible everywhere), and it _does_ have concatenation ops.
> So I don't understand what you mean.

I meant .Fixed and I meant the regular String type.  And I forgot that
concatenation isn't declared.  Blah.  Sorry for generating confusion.
For my own part, I only use String for string literals.

> I agree that blank-padding is a nearly useless thing to do.
> But you can do a lot with fixed-length strings, so long
> as you program them in a mostly-functional style.

I'm not denying any of that.  My critique is pretty much solely about
names.

> String and Unbounded_String are both strings of characters,
> so I don't see why it's "plain wrong". [...]
> Adding some (near-useless) operations on String that do blank-padding
> doesn't suddenly make String not a string type.

No, but it does create a violation of axioms that define
universal_string.  Such axioms are essentially those of a semigroup
with the trivial inverse operation where only the empty string has an
inverse.  (Perhaps we might also say "maximally non-invertible
semigroup".  )  You start adding padding manipulations in there and
these axioms are no longer true.

Speaking formally, which I was trying to do (but failing in the
details), almost-a-string is a subset of not-a-string.  Axiom
satisfaction has sharp boundaries that don't usually coincide with
ordinary conceptual boundaries.  Informally, sure, they're both
strings.  But the Ada String type, with its padding, does not satisfy
the axioms of universal_string.  The problem is that it's a fixed
array, not a fixed array allocation with a variable length like
Bounded_String.  If I assign the value "A", a String of length 1, to a
String(2), the length of its value as a universal_string changes from
1 to 2.  So even simple assignment violates the axioms.

I'm not denying that having an informally-a-string type which is a
fixed-length array is useful and efficient.  It's just not a possible
implementation of universal_string.  And it's not like you can't
interconvert, but you should probably not do so silently, because
you're not satisfying a set of common axioms.

The problem that was the nexus of the original discussion is that
string literals are of type String and not deemed elements of
universal_string.

There's a second problem, one of usability, that the default string
type ought to be Unbounded_String, because it's closest to
universal_string and would create the fewest surprises (manifested in
exceptions raised).  That's really another discussion, though.

Eric



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-13 20:02  4%                       ` Ada.Strings.Bounded Robert A Duff
@ 2008-04-13 23:20  2%                         ` Eric Hughes
  2008-04-14  9:07  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-13 23:20 UTC (permalink / raw)


On Apr 13, 2:02 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
wrote:
> The analogy is not perfect.  You can create arbitrarily large strings
> (within the limits of available memory, and the bounds of Integer,
> which is pretty big).  It's just that any particular string object
> cannot change length.  Integers are much more restricted -- you can't
> create an integer bigger than some implementation-defined limit,
> such as 32 or 64 bits.

The perspective I have is that of the relationship between groupoids
and groups (and for strings, semigroupoids and semigroups).  A
groupoid, briefly, is just like a group except that its binary
operation is a partial function rather than a total function.  The
inverse function is also partial.  This terminology means that the
binary operation isn't defined on certain pairs.  The groupoid axioms
agree with the group axioms with the proviso that this is only
required where all the groupoid operations are defined.  There also
axioms to ensure that the operation is defined where it's possible to
define it symbolically.

The canonical example of a groupoid is a checkerboard.  This is
clearly like an infinite, bi-colored plane pattern, but it doesn't
have translational group symmetries because of the boundaries.  It
does have, however, translational groupoid symmetries.

From this perspective, the analogy is exact.  Raising an exception is
the computer-language way of indicating the difference between the
domain of a total function and that of a partial function.  Arithmetic
out-of-bounds raises Constraint_Error.  Concatenating strings to make
one that's too large raises Storage_Error.  If you don't get these
exceptions, your operations are known to satisfy the defining axioms
of the type.

I don't know if anybody has developed an "-oid" morphism for category
theory that takes an axiomatic theory and maps it to its "theory-oid"
version.  This is the mathematics for a proper formal theory of the
relationship between universal types and programming-language types.
(Note: when the set of elements of a universal type are finite, the "-
oid" morphism would be the identity.)  Yet I don't think there's a
practical reason to wait for this bit of research.  Map partial
function non-definition to an exception and otherwise assume that any
defining axioms are satisfied.


Switching subjects slightly, your comment points out (to me, at least)
a small deficiency in Ada's Integer types.  I think it should be
possible to define
   type Really_Long_Natural is range 0 .. 2**256 - 1 ;
with a mandate that it always compile.  This is the proper analogue
within integer types (as I think you took it) to fixed length
strings.  In this meaning, a more direct one, the analogue of an
integer is a string of length 1.  (BTW, such a type would be useful
for implementing symmetric ciphers.)

As you point out, there's already a bignum facility within a compiler,
so doing bignum arithmetic with fixed bounds should also be possible.
Indeed, evaluating the range expression itself requires that
facility.  The same bignum facility, with small modifications, could
also serve as the implementation basis of Unbounded_Integer, presented
as a library function rather than a native type.


> Well, the limits on bignums are fundamentally different from the limits
> on Ada's integer types.  In a language with bignums, the _language_
> places no limit on the size of integers.  An implementation can
> of course run out of memory, [...]
> Unbounded strings would be similar, if they were indexed by bignums.

I take this as a report of a language defect.  An unbounded string
*must* to be indexed by an unbounded natural.  If it's not, then the
string is bounded or it's not a string (since it would then break the
indexing axioms).  Changing this shouldn't create any backward-
compatibility problems for existing code, since there's a natural
inclusion map on values from word-length-limited Naturals into
unbounded Naturals.

Caveat: For the above to make sense, the phrase "unbounded string"
preceding does not mean "Ada.Strings.Unbounded_String", but rather the
well-defined-but-not-implemementable (i.e. universal) type
universal_string.

> I don't quite understand all this stuff about user-defined
> universal types (you give syntax, but didn't fully explain
> the semantics).  But anyway, you seem to be inventing something
> like abstract types, and/or class-wide types.

I wasn't trying to completely precise because of space limitations.
But let me say outright that I am sure this idea is not an abstract
type and not a class-wide type.  For an Ada-relevant means of entry to
this idea, here's a quotation from ARM 4.5.3/1:
> The binary adding operators + (addition) and - (subtraction)
> are predefined for every specific numeric type T with their
> conventional meaning.
So where does the "conventional meaning" come from?  Imprecisely, it's
been around as long as history.  Recall, Euclid had a proof that there
was no largest number.  Precisely, it dates to the earliest days of
modern formal logic, say, the late nineteenth century.  Neither of
these definitions have anything to do with programming languages.  But
that's the key to the whole puzzle.  The mental ideas that constitute
types as values and their manipulations originate outside computers
and their programming languages.  The way that humanity has found to
think precisely about these is with the tools of formal logic.

> Note that universal_integer is conceptually the same thing
> as root_integer'Class.  The RM doesn't say that, but the
> language designers had that analogy in mind.

As I've said in so many words just above, I believe this analogy is
infelicitous.  (I really do _not_ mean "wrong" here.)  It takes the
discussion inward to more programming language ideas and leads to
infinite regress--and lack of progress.

My idea of universal_integer is the following.  Start with the symbol
"0" and the unary function "S".  All the terms (in the predicate
calculus sense) of these two symbols constitute the set of integers.
By doing this, I eliminate non-standard models.  Add the axioms of
Peano arithmetic to get addition.  Add the rest of the axioms of
arithmetic to get its ordinary operator behavior.  That set of terms
with such axioms constitute universal_integer.

There's a canonical injective interpretation mapping from Ada's
Integer into universal_integer.  This is the value map.  It is not an
identity map, because the domain and range are not the same.  This
point is subtle and critical.  The domain is the valid values of Ada's
type Integer *as it is defined in the ARM* and its range is set of
symbols paired with a set of axioms.  These aren't the same.  They
cannot possibly be the same.  Any programming language has to down-
convert the total functions of a universal type to partial functions
of an implementable one.

There's a corresponding representation mapping in the other direction;
it's a partial function (necessarily).


> The above is an odd mixture of C-like syntax and Ada-like syntax.
> And "T2 x;" should be "X: T2;"

Yeah, my slip.  I've been on a C++ project lately.

> Surely "is private and U" should be "is new U with private".

But this one I meant.  A universal type should not be directly derived
from a universal type.  So I lifted the interface syntax.  Why
shouldn't you derive from a universal type?  Because it's not
implementable!  Universal types have a whole set of interrelationships
I'm avoiding; entirely within the set of universal types there's
something just like derivation.

So I can now outline what the relationship ought to be:
-- The set of values of an implemented type is
      a _subset_ of the terms of the universal type.
-- The set of operators on an implemented type
      _satisfy_ the axioms of the universal type.
Satisfaction here is framed in terms of preconditions, postconditions,
and invariants, in other words, all the specification apparatus of
program correctness.

> I don't know what "equal as universal values" means, either.

It means (now that I've put out some apparatus) that the values of the
interpretations maps are equal as terms of the universal type.
Symbolically, its the predicate "interpretation( y1 ) =
interpretation( y2 )", where "interpretation" is a (mathematical)
function Ada.Integer --> universal_integer.

Eric




^ permalink raw reply	[relevance 2%]

* Re: Ada.Strings.Bounded
  2008-04-13 16:53  5%                     ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-13 20:10  6%                       ` Robert A Duff
  2008-04-13 23:52  4%                         ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Robert A Duff @ 2008-04-13 20:10 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 12, 1:46 pm, Georg Bauhaus <rm.tsoh.plus-
> bug.bauh...@maps.futureapps.de> wrote:
>> The fixed String is an array, a basic and central piece of Ada.
>> Unbounded_String is not an array.
>
> Sure, you can have your array; I have no issue at all with that.  But
> Ada.Strings.String is just not a string, not in the way it does
> padding, not in its absence of concatenation.

There is no such thing as Ada.Strings.String.  I thought maybe you meant
the package Ada.Strings.Fixed, but that package has no type.  It uses
the predefined type String (which is declared in Standard, and
therefore visible everywhere), and it _does_ have concatenation ops.
So I don't understand what you mean.

I agree that blank-padding is a nearly useless thing to do.
But you can do a lot with fixed-length strings, so long
as you program them in a mostly-functional style.

>> Both types use the word "string" in their name, which is
>> unfortunate.
>
> I consider it more than unfortunate.  I consider it just plain wrong.

String and Unbounded_String are both strings of characters,
so I don't see why it's "plain wrong".  It might be better
to call them Fixed_String and String, I suppose -- the
reason for the names is historical (String predates Unbounded_String).

Adding some (near-useless) operations on String that do blank-padding
doesn't suddenly make String not a string type.

- Bob



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-13 16:31  3%                     ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-13 20:02  4%                       ` Robert A Duff
  2008-04-13 23:20  2%                         ` Ada.Strings.Bounded Eric Hughes
  0 siblings, 1 reply; 200+ results
From: Robert A Duff @ 2008-04-13 20:02 UTC (permalink / raw)


Eric Hughes <eric.eh9@gmail.com> writes:

> On Apr 12, 3:09 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> So a comparable case would be Integer vs. BigNum. The latter
>> (arbitrary-precision arithmetic) plays same role for integers as
>> Unbounded_String does for strings.

The analogy is not perfect.  You can create arbitrarily large strings
(within the limits of available memory, and the bounds of Integer,
which is pretty big).  It's just that any particular string object
cannot change length.  Integers are much more restricted -- you can't
create an integer bigger than some implementation-defined limit,
such as 32 or 64 bits.

>...Now, if ARM had BigNum defined, we would
>> experience exactly same problems with both, as we have with Strings and
>> Unbounded_String.
>
> Well, yes; that's a good second example, although let's call it
> Unbounded_Integer.  The mechanisms are identical for dealing with
> universal_string/String/Unbounded_String and univeral_integer/Integer/
> Unbounded_Integer.  In the first case we have (0=absent,1=present)
> 0/1/1 and in the second we have 1/1/0.  In the first case we have
> endless type conversions to do ordinary work.  In the second we have
> an absence in the standard.

It's particularly annoying that Ada doesn't allow bignums,
because every Ada implementation must support a bignum package
-- compile-time arithmetic (static expressions) require it.
So every Ada implementer has to go to all that trouble,
but can't provide that functionality to users at run time -- at
least, not in a standard way.

> On Sat, 12 Apr 2008 11:50:56 -0700 (PDT), Eric Hughes wrote:
>> I believe many of the issues involving strings could be addressed by
>> introducing a predefined type universal_string.
>
> On Apr 12, 3:09 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> I don't see it this way.
>
> I have a strong counterclaim--I don't think it can be solved without
> introducing such a type.

> Here's the real rub: universal_integer and universal_string are each
> _unimplementable_ as executable types.  As abstract mathematical
> types, they're perfectly well-defined.  The origin of the difference
> is that universal types have no possible bound in size.  Since every
> computer type has such a bound, there's a fundamental disjunct between
> these two.  An unbounded type actually does have a bound--it throws an
> exception when its internal bounds are exceeded.  A hypothetical
> implementation of a universal type would be unable *in principle* to
> throw such an exception.  This is clearly contrary to fact, where
> every program can run out of memory.

Well, the limits on bignums are fundamentally different from the limits
on Ada's integer types.  In a language with bignums, the _language_
places no limit on the size of integers.  An implementation can
of course run out of memory, but that's not a limit on the size
of any particular integer type, and the "limit" depends not only
on how much memory you have, but also on how much you're using for
something else.

Unbounded strings would be similar, if they were indexed by bignums.

> If this sounds like my idea for partial type specification (one
> without code), it should.  These ideas come from the same perspective.
>
> There's no concept (except _ad hoc_ in the ARM) of what a universal,
> unimplementable type is; there's certainly no way of declaring one.
> So here's the very beginning of a proposal.  To declare and define
> such a type:
>
>     universal_type_definition ::= *universal* *type*
> defining_identifier [known_discriminant_part] *;*

I don't quite understand all this stuff about user-defined
universal types (you give syntax, but didn't fully explain
the semantics).  But anyway, you seem to be inventing something
like abstract types, and/or class-wide types.

Note that universal_integer is conceptually the same thing
as root_integer'Class.  The RM doesn't say that, but the
language designers had that analogy in mind.

>    universal type U ;
>    function op( U Object ) return U ;
>    type T1 is private and U ;
>    type T2 is private and U ;
>    overriding function op( T1 Object ) return T1 ;
>    overriding function op( T2 Object ) return T2 ;
>    function U( T2 Object ) return T1 ;
>    T2 x ;
>    T1 y1 := T1.op( U( x ) ) ;
>    T1 y2 := U( T2.op( x ) ) ;
>    T1 y := x.op ;

The above is an odd mixture of C-like syntax and Ada-like syntax.
Surely "is private and U" should be "is new U with private".
And "T2 x;" should be "X: T2;"

> The expressions for y1 and y2 should be interchangeable as
> implementations for the expression for y.  The point of the
> declarations is to give unambiguous semantics to the expression
> "x.op", so that it does not matter to the correctness of the program
> what implementation expression the compiler chooses.  If Usenet had
> better formatting, I'd draw a commutative diagram as an illustration.

I don't see any semantics, unambiguous or otherwise, in the above.
Sorry -- I just can't guess what it means.

> There's special meaning behind the conversion function U.  Its
> mandatory semantics is to convert an object of T2 to one of T1, such
> that their values are equal as universal values.

I don't know what "equal as universal values" means, either.

Anyway, the problem with Unbounded_Strings, as I see it,
is that Ada doesn't allow user-defined types to use all
the same notations as the built-in ones.  Literals,
indexing, etc.

- Bob



^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  2008-04-12 19:46  5%                   ` Ada.Strings.Bounded Georg Bauhaus
@ 2008-04-13 16:53  5%                     ` Eric Hughes
  2008-04-13 20:10  6%                       ` Ada.Strings.Bounded Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-13 16:53 UTC (permalink / raw)


On Apr 12, 1:46 pm, Georg Bauhaus <rm.tsoh.plus-
bug.bauh...@maps.futureapps.de> wrote:
> The fixed String is an array, a basic and central piece of Ada.
> Unbounded_String is not an array.

Sure, you can have your array; I have no issue at all with that.  But
Ada.Strings.String is just not a string, not in the way it does
padding, not in its absence of concatenation.

> Both types use the word "string" in their name, which is
> unfortunate.

I consider it more than unfortunate.  I consider it just plain wrong.


> Seen from this point of view, a more general question is,
> do we have standard ways of converting between arrays and lists?
> Should these conversions be captured by some "predefined" notion
> of universal_array?

No.  But this answer is one that hinges on the specifics of the
question, not on generalities.  Arrays have a fixed number of
elements; lists do not.  This is more than a matter of
implementation.  It's a question of specification.

Now these two types do share the property that they are indexable.  A
proper set of universal declarations should be able to capture this
similarity.  This requires a partial specification, in my view, and
that subject is beyond the scope of this message, except to say that
partial specifications and universal types are orthogonal concepts.

Hidden in your question, though, is another issue.  I don't believe
that conversions should be automatic.  I believe they should be
explicitly declared and explicitly defined.

> Unfortunately, programming always deals with storage, memory,
> and times, in particular when a systems programming language
> like Ada is used, and when credit is given to the fact that
> programs mean operations of a computer with storage cells,
> instructions, and clock ticks. I can imagine values of some
> underlying universal_array as part of a nice clean
> ivory tower model of mathematical reductionism. Nasty real
> world computers ;)

There's a pattern in dealing with this issue that deserves
standardization with respect to universal types.
   -- When return is ordinary, then the result adheres to the
universal definition.
   -- When return is exceptional, then there is no requirement that
there's any adherence.
Thus exceptions kick you out of the mathematical assumptions into the
real world, and they do so in a reasonably controlled way.

Eric




^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-12 21:09  5%                   ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-13 16:31  3%                     ` Eric Hughes
  2008-04-13 20:02  4%                       ` Ada.Strings.Bounded Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Eric Hughes @ 2008-04-13 16:31 UTC (permalink / raw)


On Apr 12, 3:09 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> So a comparable case would be Integer vs. BigNum. The latter
> (arbitrary-precision arithmetic) plays same role for integers as
> Unbounded_String does for strings. Now, if ARM had BigNum defined, we would
> experience exactly same problems with both, as we have with Strings and
> Unbounded_String.

Well, yes; that's a good second example, although let's call it
Unbounded_Integer.  The mechanisms are identical for dealing with
universal_string/String/Unbounded_String and univeral_integer/Integer/
Unbounded_Integer.  In the first case we have (0=absent,1=present)
0/1/1 and in the second we have 1/1/0.  In the first case we have
endless type conversions to do ordinary work.  In the second we have
an absence in the standard.


On Sat, 12 Apr 2008 11:50:56 -0700 (PDT), Eric Hughes wrote:
> I believe many of the issues involving strings could be addressed by
> introducing a predefined type universal_string.

On Apr 12, 3:09 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> I don't see it this way.

I have a strong counterclaim--I don't think it can be solved without
introducing such a type.

Here's the real rub: universal_integer and universal_string are each
_unimplementable_ as executable types.  As abstract mathematical
types, they're perfectly well-defined.  The origin of the difference
is that universal types have no possible bound in size.  Since every
computer type has such a bound, there's a fundamental disjunct between
these two.  An unbounded type actually does have a bound--it throws an
exception when its internal bounds are exceeded.  A hypothetical
implementation of a universal type would be unable *in principle* to
throw such an exception.  This is clearly contrary to fact, where
every program can run out of memory.

If this sounds like my idea for partial type specification (one
without code), it should.  These ideas come from the same perspective.

There's no concept (except _ad hoc_ in the ARM) of what a universal,
unimplementable type is; there's certainly no way of declaring one.
So here's the very beginning of a proposal.  To declare and define
such a type:

    universal_type_definition ::= *universal* *type*
defining_identifier [known_discriminant_part] *;*

Notice the absence of the keyword "is".  Also notice that the
declaration and definition are the same.  The point is that a
universal type _is not_ anything insofar as record declaration or
anything else that might act as a representation.  A universal type
can not have a representation (not just "may not").  If it had a
representation, it would not be universal.  This is not merely a
practicality; this is categorical.

Now like other types, you could declare operations on universal
types.  But every such operation would also be unimplementable, so
they're declaration-only.  They cannot be defined, since there's no
representation to work with.

As with an interface, an ordinary type T could derive from a universal
type U.  It could override operations from the universal type.  But
since U has no implementation, such a derivation has no effect on the
representation of T.  The result of overriding would be to bind both
the syntax and semantics of U to that of T.  With only a single such
T, an overriding declaration would be meaningless and of no effect.
With two such declarations, however, the benefits begin.  The meaning
of such a pair of declarations says that the semantics of the two
operations are identical when values of one type are substituted for
that of the other _when those values are considered as universal
values_ (and thus not as represented values within an implementation).

With such a syntax, you obtain the ability to make a well-formed
formula with clearly defined semantics.  It says nothing about
compilation.  I consider this an advantage, as it is the essence of
separate compilation.  Getting to an unambiguous expression is the
first step.

Now, about compilation, a formula with well-defined semantics does not
(in general) have well-defined pragmatics.  The formula itself does
not specify how long execution should take, what functions must be
called, etc.  All the formula as such says is what the results should
be.  A simple example:

   universal type U ;
   function op( U Object ) return U ;
   type T1 is private and U ;
   type T2 is private and U ;
   overriding function op( T1 Object ) return T1 ;
   overriding function op( T2 Object ) return T2 ;
   function U( T2 Object ) return T1 ;
   T2 x ;
   T1 y1 := T1.op( U( x ) ) ;
   T1 y2 := U( T2.op( x ) ) ;
   T1 y := x.op ;

The expressions for y1 and y2 should be interchangeable as
implementations for the expression for y.  The point of the
declarations is to give unambiguous semantics to the expression
"x.op", so that it does not matter to the correctness of the program
what implementation expression the compiler chooses.  If Usenet had
better formatting, I'd draw a commutative diagram as an illustration.

There's special meaning behind the conversion function U.  Its
mandatory semantics is to convert an object of T2 to one of T1, such
that their values are equal as universal values.

Eric



^ permalink raw reply	[relevance 3%]

* Re: Ada.Strings.Bounded
  2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
  2008-04-12 19:46  5%                   ` Ada.Strings.Bounded Georg Bauhaus
@ 2008-04-12 21:09  5%                   ` Dmitry A. Kazakov
  2008-04-13 16:31  3%                     ` Ada.Strings.Bounded Eric Hughes
  2008-04-14 15:11  6%                   ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2008-04-12 21:09 UTC (permalink / raw)


On Sat, 12 Apr 2008 11:50:56 -0700 (PDT), Eric Hughes wrote:

> I believe many of the issues involving strings could be addressed by
> introducing a predefined type universal_string.

I don't see it this way. You have mentioned universal_integer, which is
already here. So a comparable case would be Integer vs. BigNum. The latter
(arbitrary-precision arithmetic) plays same role for integers as
Unbounded_String does for strings. Now, if ARM had BigNum defined, we would
experience exactly same problems with both, as we have with Strings and
Unbounded_String.

> Now, my real hope is that universal_string wouldn't need to be
> predefined at all, but specified algebraically or logically within a
> future version of Ada.

I can only agree with that.

But note, that in order to do so, you will need slices, indices and sets of
indices (ranges is an example of) defined algebraically as well. Presently
Ada lacks them.

The bottom line, instead of patching it here and there, the language type
system should be redesigned. Hacks need to be replaced by sound
concepts.[*]  Unfortunately Ada community has little interest in that.

----------
* By this I don't mean backward incompatibility. Actually it is the hacks,
which are responsible for most of incompatibilities, as they tend to
introduce strange syntax, new reserved words and confusing semantics. 

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



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
@ 2008-04-12 19:46  5%                   ` Georg Bauhaus
  2008-04-13 16:53  5%                     ` Ada.Strings.Bounded Eric Hughes
  2008-04-12 21:09  5%                   ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-14 15:11  6%                   ` Ada.Strings.Bounded Adam Beneschan
  2 siblings, 1 reply; 200+ results
From: Georg Bauhaus @ 2008-04-12 19:46 UTC (permalink / raw)


Eric Hughes wrote:
> On Apr 5, 3:43 am, Pascal Obry <pas...@obry.net> wrote:
>>     What to do if we have Put_Line defined for String and
>>     Unbounded_String? Which version gets called?
> 
> I know this answer is a bit heretical, but the answer I'd pick is
> "either one".  Non-deterministic execution, if you'd like the
> technical term.  Which in practice means that the compiler can pick a
> deterministic path and just use that one.
> 
> The reason for this is that String and Unbounded_String are not
> arbitrarily related in conception.  Ada, as presently constituted, is
> unable of representing the details of this relationship.  Users of
> these types know what they're supposed to do, but the language does
> not capture this.  A correct implementation of Put_Line should have
> the property that the result of Put_Line on a String is the same as
> the result of Put_Line on an Unbounded_String converted from the same
> String.  This is the substance of algebraic specification.  So,
> assuming (contrary to fact) such a specification, it should not matter
> for correctness which version executed.
> 
> It would affect performance, true.  But it's performance about
> symbolic manipulations (in the representation of the type) with
> symbols that do not appear in the language itself.  Since these
> symbols do not appear in the definition of String, it's the wrong path
> to try to specify performance choices _at this level of abstraction_.
> Some form of (expanded) representation clause is the right place to do
> this.  Representation clauses are the natural way in Ada to specify
> implementation choices.
> 
> Back the larger type issue, the ARM contains the types
> universal_integer, universal_real, universal_fixed; these are listed
> as predefined in ARM 3.2.1/10.  (Erratum: not all the predefined types
> are listed here.)  I find it droll that the term "predefined" is not
> defined.  It doesn't need to be, really, though.  "Everybody knows"
> what numbers are supposed to do.  The axioms of arithmetic are well-
> known, even if all the ordinary numbers of mathematics are
> unimplementable on computers (only bounded-length representations are,
> even if the bound is indefinite).
> 
> I believe many of the issues involving strings could be addressed by
> introducing a predefined type universal_string.  And then the hard
> part: making everything work out right.  _Inter alia_, all conversions
> between string types would have to preserve the underlying
> universal_string value.  I would raise Length_Error if a silent
> truncation were to occur, under the theory that truncation is an
> operation on values (as distinguished from objects and variables) that
> should *never* be made silently.  And having universal_string should
> eliminate most of those unary conversion operators to move between
> different string types.

The fixed String is an array, a basic and central piece of Ada.
Unbounded_String is not an array.

Both types use the word "string" in their name, which is
unfortunate.  They are two very different constructions.
We can use Unbounded_String objects in ways that
are not available with strings: they are lists rather
than fixed arrays.

Seen from this point of view, a more general question is,
do we have standard ways of converting between arrays and lists?
Should these conversions be captured by some "predefined" notion
of universal_array? (Maybe you will find ideas by Dmitry Kazakov
instructive.)

Unfortunately, programming always deals with storage, memory,
and times, in particular when a systems programming language
like Ada is used, and when credit is given to the fact that
programs mean operations of a computer with storage cells,
instructions, and clock ticks. I can imagine values of some
underlying universal_array as part of a nice clean
ivory tower model of mathematical reductionism. Nasty real
world computers ;)

The APL world is different and offers another hint. Maybe
Ada fixed Strings let us think they somehow must have one
dimension, but not 2, 3, or N. Why?
And should universal_array be made capable enough to convert
arrays to lists and vice versa per dimension?



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-05  9:43  5%               ` Ada.Strings.Bounded Pascal Obry
  2008-04-05 10:10  5%                 ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-05 11:36  5%                 ` Ada.Strings.Bounded Gautier
@ 2008-04-12 18:50  3%                 ` Eric Hughes
  2008-04-12 19:46  5%                   ` Ada.Strings.Bounded Georg Bauhaus
                                     ` (2 more replies)
  2 siblings, 3 replies; 200+ results
From: Eric Hughes @ 2008-04-12 18:50 UTC (permalink / raw)


On Apr 5, 3:43 am, Pascal Obry <pas...@obry.net> wrote:
>     What to do if we have Put_Line defined for String and
>     Unbounded_String? Which version gets called?

I know this answer is a bit heretical, but the answer I'd pick is
"either one".  Non-deterministic execution, if you'd like the
technical term.  Which in practice means that the compiler can pick a
deterministic path and just use that one.

The reason for this is that String and Unbounded_String are not
arbitrarily related in conception.  Ada, as presently constituted, is
unable of representing the details of this relationship.  Users of
these types know what they're supposed to do, but the language does
not capture this.  A correct implementation of Put_Line should have
the property that the result of Put_Line on a String is the same as
the result of Put_Line on an Unbounded_String converted from the same
String.  This is the substance of algebraic specification.  So,
assuming (contrary to fact) such a specification, it should not matter
for correctness which version executed.

It would affect performance, true.  But it's performance about
symbolic manipulations (in the representation of the type) with
symbols that do not appear in the language itself.  Since these
symbols do not appear in the definition of String, it's the wrong path
to try to specify performance choices _at this level of abstraction_.
Some form of (expanded) representation clause is the right place to do
this.  Representation clauses are the natural way in Ada to specify
implementation choices.

Back the larger type issue, the ARM contains the types
universal_integer, universal_real, universal_fixed; these are listed
as predefined in ARM 3.2.1/10.  (Erratum: not all the predefined types
are listed here.)  I find it droll that the term "predefined" is not
defined.  It doesn't need to be, really, though.  "Everybody knows"
what numbers are supposed to do.  The axioms of arithmetic are well-
known, even if all the ordinary numbers of mathematics are
unimplementable on computers (only bounded-length representations are,
even if the bound is indefinite).

I believe many of the issues involving strings could be addressed by
introducing a predefined type universal_string.  And then the hard
part: making everything work out right.  _Inter alia_, all conversions
between string types would have to preserve the underlying
universal_string value.  I would raise Length_Error if a silent
truncation were to occur, under the theory that truncation is an
operation on values (as distinguished from objects and variables) that
should *never* be made silently.  And having universal_string should
eliminate most of those unary conversion operators to move between
different string types.

As not-too-much of an aside, this is why the ordinary Strings package
is fatally flawed, because its padding manipulations are just NOT how
universal_string values act.  Padding is a bastard child of an
implementation choice (fixed length array) and a discrimination
between characters that matter and the padding character, which
doesn't.  That package should really be named Padded_Strings.

Now, my real hope is that universal_string wouldn't need to be
predefined at all, but specified algebraically or logically within a
future version of Ada.  But for now the next step is to start with a
predefined type.

Eric



^ permalink raw reply	[relevance 3%]

* Re: Ada.Strings.Bounded
  2008-04-07 16:34  6%                         ` Ada.Strings.Bounded stefan-lucks
@ 2008-04-07 17:34  6%                           ` (see below)
  0 siblings, 0 replies; 200+ results
From: (see below) @ 2008-04-07 17:34 UTC (permalink / raw)


On 07/04/2008 17:34, in article
Pine.LNX.4.64.0804071812200.15920@medsec1.medien.uni-weimar.de,
"stefan-lucks@see-the.signature" <stefan-lucks@see-the.signature> wrote:

>>> The only useful use for "+" in Ada is for conversions.
>> 
>> OK, so that's not much of a use.  On the other hand, the idea that "+"
>> represents the identity function is ingrained enough in me that I've
>> resisted using it for a conversion operator even though others around
>> me have been doing that.  Call it an obstinate adherence to
>> meaningless purity or whatever.  But like Randy, I would have
>> preferred adding one (maybe even two) operator symbols that would have
>> no meaning except that the user could define them, although I'm not
>> sure about "#" since that already has a use (in based numeric
>> literals).  I'd prefer something not currently used at all, like "@"
>> or "!" or tilde.  Of course, it apparently isn't going to happen
>> anyway so there's not much point arguing about which character would
>> be best.
> 
> Two natural candidates which come into my mind would be an unary '&' and
> the '%'-sign:
> 
>   '%' (percent) indicates some kind of conversion anyway (though usually
>       in postfix notation, not as a prefix, "75 %" for 75/100).

Potential problems there with string literals (see RM: J.2 Allowed
Replacements of Characters)?

-- 
Bill Findlay
<surname><forename> chez blueyonder.co.uk





^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-07 14:57  5%                       ` Ada.Strings.Bounded Adam Beneschan
  2008-04-07 15:23  6%                         ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-07 16:34  6%                         ` stefan-lucks
  2008-04-07 17:34  6%                           ` Ada.Strings.Bounded (see below)
  1 sibling, 1 reply; 200+ results
From: stefan-lucks @ 2008-04-07 16:34 UTC (permalink / raw)


> > The only useful use for "+" in Ada is for conversions.
> 
> OK, so that's not much of a use.  On the other hand, the idea that "+"
> represents the identity function is ingrained enough in me that I've
> resisted using it for a conversion operator even though others around
> me have been doing that.  Call it an obstinate adherence to
> meaningless purity or whatever.  But like Randy, I would have
> preferred adding one (maybe even two) operator symbols that would have
> no meaning except that the user could define them, although I'm not
> sure about "#" since that already has a use (in based numeric
> literals).  I'd prefer something not currently used at all, like "@"
> or "!" or tilde.  Of course, it apparently isn't going to happen
> anyway so there's not much point arguing about which character would
> be best.

Two natural candidates which come into my mind would be an unary '&' and 
the '%'-sign:

  '%' (percent) indicates some kind of conversion anyway (though usually 
      in postfix notation, not as a prefix, "75 %" for 75/100). 

  '&' is something you can even now use for conversion into strings and 
      the like:
        declare an appropriate function 
            function "&" (X: String; Y: Some_Type) return String;
        and then just write 
	    "" & A;
        wherever you need A being converted into a string. 
      A unary "&" would be handy -- prepending the empty string clearly is 
      artificial. 

So long

Stefan

-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------




^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-07 14:57  5%                       ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-07 15:23  6%                         ` Dmitry A. Kazakov
  2008-04-07 16:34  6%                         ` Ada.Strings.Bounded stefan-lucks
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-07 15:23 UTC (permalink / raw)


On Mon, 7 Apr 2008 07:57:55 -0700 (PDT), Adam Beneschan wrote:

> But like Randy, I would have
> preferred adding one (maybe even two) operator symbols that would have
> no meaning except that the user could define them, although I'm not
> sure about "#" since that already has a use (in based numeric
> literals).  I'd prefer something not currently used at all, like "@"
> or "!" or tilde.

May I suggest Unicode Character 'NO-BREAK SPACE' (U+00A0)?

Sorry, just could not resist (:-))

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



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-06  0:31  6%                     ` Ada.Strings.Bounded Randy Brukardt
@ 2008-04-07 14:57  5%                       ` Adam Beneschan
  2008-04-07 15:23  6%                         ` Ada.Strings.Bounded Dmitry A. Kazakov
  2008-04-07 16:34  6%                         ` Ada.Strings.Bounded stefan-lucks
  0 siblings, 2 replies; 200+ results
From: Adam Beneschan @ 2008-04-07 14:57 UTC (permalink / raw)


On Apr 5, 5:31 pm, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> "Pascal Obry" <pas...@obry.net> wrote in message
>
> news:47F76D31.2090009@obry.net...
>
> > Gautier,
>
> > >   function S (Source : Ada.Strings.Unbounded.Unbounded_String) return
> > > String
> > >     renames Ada.Strings.Unbounded.To_String;
> > >   function U (Source : String) return
> > > Ada.Strings.Unbounded.Unbounded_String
> > >     renames Ada.Strings.Unbounded.To_Unbounded_String;
>
> > I'm doing the same with operator "+" and "-", but I'm not happy with
> > that. You do not need the parenthesis with operators:
>
> The only useful use for "+" in Ada is for conversions.

Well, I can think of one other potentially useful use: with a numeric
argument (especially a numeric literal, or something like pi).  It
doesn't have any effect but could serve to make things clearer in some
mathematical cases.  Maybe you'd call a bounded integration routine
with +1.0 and -1.0 as the arguments.

OK, so that's not much of a use.  On the other hand, the idea that "+"
represents the identity function is ingrained enough in me that I've
resisted using it for a conversion operator even though others around
me have been doing that.  Call it an obstinate adherence to
meaningless purity or whatever.  But like Randy, I would have
preferred adding one (maybe even two) operator symbols that would have
no meaning except that the user could define them, although I'm not
sure about "#" since that already has a use (in based numeric
literals).  I'd prefer something not currently used at all, like "@"
or "!" or tilde.  Of course, it apparently isn't going to happen
anyway so there's not much point arguing about which character would
be best.

                               -- Adam




^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-05 12:14  6%                   ` Ada.Strings.Bounded Pascal Obry
@ 2008-04-06  0:31  6%                     ` Randy Brukardt
  2008-04-07 14:57  5%                       ` Ada.Strings.Bounded Adam Beneschan
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2008-04-06  0:31 UTC (permalink / raw)


"Pascal Obry" <pascal@obry.net> wrote in message
news:47F76D31.2090009@obry.net...
> Gautier,
>
> >   function S (Source : Ada.Strings.Unbounded.Unbounded_String) return
> > String
> >     renames Ada.Strings.Unbounded.To_String;
> >   function U (Source : String) return
> > Ada.Strings.Unbounded.Unbounded_String
> >     renames Ada.Strings.Unbounded.To_Unbounded_String;
>
> I'm doing the same with operator "+" and "-", but I'm not happy with
> that. You do not need the parenthesis with operators:

The only useful use for "+" in Ada is for conversions. So it is a common
convention (I use it sometimes). We actually considered adding that rename
to the strings packages, but enough people thought it was ugly that it
wasn't done. (It needs getting used to, thus the hope of making the intent
clearer by including it in the packages.)

We also briefly considered adding an operator symbol specifically for this
purpose. Something like
   function "#" (Source : String) return Unbounded_String;
But the people who don't think "+" is ugly were against this, because we
already have such an operator and thus don't need another one. Thus a
deadlock. Sigh.

>    external_packer: array(External) of Unbounded_String:=
>      ( +"zip.exe",
>        +"7z.exe",
>        +"kzip.exe");
>
> Better than nothing...

I agree, and it doesn't look so ugly if you can think of unary "+" as the
conversion operator. (Personally, I'd prefer a different symbol for this
purpose, but "+" has the advantage of actually working now.)

                               Randy.





^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-05 11:36  5%                 ` Ada.Strings.Bounded Gautier
@ 2008-04-05 12:14  6%                   ` Pascal Obry
  2008-04-06  0:31  6%                     ` Ada.Strings.Bounded Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Pascal Obry @ 2008-04-05 12:14 UTC (permalink / raw)
  To: Gautier

Gautier,

>   function S (Source : Ada.Strings.Unbounded.Unbounded_String) return 
> String
>     renames Ada.Strings.Unbounded.To_String;
>   function U (Source : String) return 
> Ada.Strings.Unbounded.Unbounded_String
>     renames Ada.Strings.Unbounded.To_Unbounded_String;

I'm doing the same with operator "+" and "-", but I'm not happy with 
that. You do not need the parenthesis with operators:

   external_packer: array(External) of Unbounded_String:=
     ( +"zip.exe",
       +"7z.exe",
       +"kzip.exe");

Better than nothing...

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[relevance 6%]

* Re: Ada.Strings.Bounded
  2008-04-05  9:43  5%               ` Ada.Strings.Bounded Pascal Obry
  2008-04-05 10:10  5%                 ` Ada.Strings.Bounded Dmitry A. Kazakov
@ 2008-04-05 11:36  5%                 ` Gautier
  2008-04-05 12:14  6%                   ` Ada.Strings.Bounded Pascal Obry
  2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
  2 siblings, 1 reply; 200+ results
From: Gautier @ 2008-04-05 11:36 UTC (permalink / raw)


Pascal Obry wrote:

...
> With Unbounded_String we are close to something "usable".

That's clear. I think Adam's question was really specific to the bounded 
strings. Unbounded_String is the most comfortable and the safest, but needs 
dynamic allocation behind the scenes, which can be a handicap on some special 
situations (performance-critical, systems without dynamic allocation,...).

>    U1 : Unbounded_String;
>    U2 : Unbounded_String;
> 
>    U1 := U2;
> 
> Works fine! But then it becomes a bit messy when converting back and 
> forth with the string type.
> 
>    U1 := To_Unbounded_String ("whatever");
> 
>    Put_Line (To_String (U1));
> 
> Not a big deal, but if we can find a nice way to tell that such routine 
> must be used for conversion between type it will be quite handy.
> 
>    type Unbounded_String is ...;
> 
>    function To_String (U : Unbounded_String) return String;
> 
>    for Unbounded_String'Conversion (String) use To_String;
> 
> Just to get the idea, then one could write:
> 
>    Put_Line (U1);
> 
> Of course this raises some questions:
> 
>    What to do if we have Put_Line defined for String and
>    Unbounded_String? Which version gets called?
> 
> ...
> 
> Anyway that's just some wild thoughts :)

I agree with Dmitry that it would lead to confusing situations, something that 
Ada normally tries to avoid...
What I'm doing to make life easier is to paste the following lines in my sources

   function S (Source : Ada.Strings.Unbounded.Unbounded_String) return String
     renames Ada.Strings.Unbounded.To_String;
   function U (Source : String) return Ada.Strings.Unbounded.Unbounded_String
     renames Ada.Strings.Unbounded.To_Unbounded_String;

After the sources only need short S(...)'s and U(...)'s which are ok to me:

   external_packer: array(External) of Unbounded_String:=
     ( U("zip.exe"),
       U("7z.exe"),
       U("kzip.exe")
     );
...
   return "External: " & S(external_title(a)) & ", " & S(external_options(a));
...
       e.name:= U(unique_name);
..., etc. etc.
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-05  9:43  5%               ` Ada.Strings.Bounded Pascal Obry
@ 2008-04-05 10:10  5%                 ` Dmitry A. Kazakov
  2008-04-05 11:36  5%                 ` Ada.Strings.Bounded Gautier
  2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-05 10:10 UTC (permalink / raw)


On Sat, 05 Apr 2008 11:43:39 +0200, Pascal Obry wrote:

> Works fine! But then it becomes a bit messy when converting back and 
> forth with the string type.
> 
>     U1 := To_Unbounded_String ("whatever");
> 
>     Put_Line (To_String (U1));
> 
> Not a big deal, but if we can find a nice way to tell that such routine 
> must be used for conversion between type it will be quite handy.
> 
>     type Unbounded_String is ...;
> 
>     function To_String (U : Unbounded_String) return String;
> 
>     for Unbounded_String'Conversion (String) use To_String;

No, that would be a can of worms. Arbitrary type conversions automatically
applied is a mess. Below you immediately spot the problem of conversions
preferences. Because conversions are arbitrary, there is no any order
defined on the types to make a choice.

What is actually needed is to say that Unbounded_String is a member of
String'Class and you wanted to inherit everything form String.

The implementation of inheritance (by the compiler) will require you to
provide two *private* conversion functions when the types are untagged.
Note that you need two conversions: a forward conversion for in-parameters
and a backward conversion for out-ones. In out parameters will use both
(copy-in, copy-out).

For tagged [actually, by-reference] types the compiler can generate
conversions because they are necessarily view conversions.

> Just to get the idea, then one could write:
> 
>     Put_Line (U1);
> 
> Of course this raises some questions:
> 
>     What to do if we have Put_Line defined for String and
>     Unbounded_String? Which version gets called?

It will one of Unbounded_String, because that will be an override.

Note though, that Put_Line (File, String) will open further questions. Is
it primitive in File or in String? Clearly it should be in both. This is
how multiple dispatch issue comes in.

> Anyway that's just some wild thoughts :)

It is not wild, it is how Ada types system should be completed.

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



^ permalink raw reply	[relevance 5%]

* Re: Ada.Strings.Bounded
  2008-04-05  4:39 10%             ` Ada.Strings.Bounded Gautier
@ 2008-04-05  9:43  5%               ` Pascal Obry
  2008-04-05 10:10  5%                 ` Ada.Strings.Bounded Dmitry A. Kazakov
                                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Pascal Obry @ 2008-04-05  9:43 UTC (permalink / raw)
  To: Gautier

Gautier,

> Do you mean something like that ?

No quite as:

    B1 : BorString (10);
    B2 : BorString (20);

    B1 := B2;
    --  will raises constraint error

With Unbounded_String we are close to something "usable".

    U1 : Unbounded_String;
    U2 : Unbounded_String;

    U1 := U2;

Works fine! But then it becomes a bit messy when converting back and 
forth with the string type.

    U1 := To_Unbounded_String ("whatever");

    Put_Line (To_String (U1));

Not a big deal, but if we can find a nice way to tell that such routine 
must be used for conversion between type it will be quite handy.

    type Unbounded_String is ...;

    function To_String (U : Unbounded_String) return String;

    for Unbounded_String'Conversion (String) use To_String;

Just to get the idea, then one could write:

    Put_Line (U1);

Of course this raises some questions:

    What to do if we have Put_Line defined for String and
    Unbounded_String? Which version gets called?

...

Anyway that's just some wild thoughts :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[relevance 5%]

* Re: Ada.Bounded_Strings
  2008-04-05  4:55  0%               ` Ada.Bounded_Strings Randy Brukardt
@ 2008-04-05  7:30  0%                 ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2008-04-05  7:30 UTC (permalink / raw)


On Fri, 4 Apr 2008 23:55:56 -0500, Randy Brukardt wrote:

> "Adam Beneschan" <adam@irvine.com> wrote in message
> news:444c0bf9-a2ad-4280-8d69-58d59938f69e@d2g2000pra.googlegroups.com...
> ...
>> Again, this doesn't sound reasonable in the context of the sort of
>> "business applications" that I used to work on in COBOL.  For other
>> types of applications, it's probably OK, or Ada.Strings.Unbounded may
>> be best.  The reason I'm even thinking about all this is that I had
>> been hoping for a number of years now that Ada would be able to make
>> inroads into "business" applications and maybe be seen as an
>> alternative to COBOL, and I'm a bit disappointed that, AFAIK, nothing
>> or very little has happened in that arena.  Not that I think
>> Ada.Strings.Bounded is a major reason for this, or that providing a
>> better string-handling facility would help at all.  (shrug)
> 
> I think that the inability to write a package that "naturally" uses literals
> (and possibly indexing and slicing) for a private type are also large
> impediments.

+ classes of all types. All string types shall become members of one class.

> (Worse, the current string packages cannot be retrofitted to
> use such a capability even if it was added to Ada, lessening the possibility
> of doing that.)

Why is this a problem? Old packages could be re-implemented using new
features with the specifications left as-is for backward compatibility.

> Net-net, I think the string packages are a disaster: just good enough to
> prevent them from being properly replaced, but not good enough to use in a
> natural way. (And Ada doesn't do anything useful to support UTF-8, which
> doesn't help matters any.)

I see encodings as a different and more difficult problem. All strings are
implementations of an abstract array interface. With different encoding not
only the arrays, but also their elements will have a class: ASCII, Latin-1,
UCS-2, full Unicode. I have no idea how to handle that keeping all strings
in one class. Further, there is the presentation layer (when, say, UTF-8 is
seen as a sequence of octets). I am not sure if that need to be exposed.
Probably it has to be in order to interface other languages.

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



^ permalink raw reply	[relevance 0%]

* Re: Ada.Bounded_Strings
  2008-04-05  1:46  4%             ` Ada.Bounded_Strings Adam Beneschan
@ 2008-04-05  4:55  0%               ` Randy Brukardt
  2008-04-05  7:30  0%                 ` Ada.Bounded_Strings Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Randy Brukardt @ 2008-04-05  4:55 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> wrote in message
news:444c0bf9-a2ad-4280-8d69-58d59938f69e@d2g2000pra.googlegroups.com...
...
> Again, this doesn't sound reasonable in the context of the sort of
> "business applications" that I used to work on in COBOL.  For other
> types of applications, it's probably OK, or Ada.Strings.Unbounded may
> be best.  The reason I'm even thinking about all this is that I had
> been hoping for a number of years now that Ada would be able to make
> inroads into "business" applications and maybe be seen as an
> alternative to COBOL, and I'm a bit disappointed that, AFAIK, nothing
> or very little has happened in that arena.  Not that I think
> Ada.Strings.Bounded is a major reason for this, or that providing a
> better string-handling facility would help at all.  (shrug)

I think that the inability to write a package that "naturally" uses literals
(and possibly indexing and slicing) for a private type are also large
impediments. (Worse, the current string packages cannot be retrofitted to
use such a capability even if it was added to Ada, lessening the possibility
of doing that.)

Net-net, I think the string packages are a disaster: just good enough to
prevent them from being properly replaced, but not good enough to use in a
natural way. (And Ada doesn't do anything useful to support UTF-8, which
doesn't help matters any.)

                          Randy.





^ permalink raw reply	[relevance 0%]

* Re: Ada.Strings.Bounded
  2008-04-04 21:15 12%           ` Ada.Strings.Bounded Adam Beneschan
@ 2008-04-05  4:39 10%             ` Gautier
  2008-04-05  9:43  5%               ` Ada.Strings.Bounded Pascal Obry
  0 siblings, 1 reply; 200+ results
From: Gautier @ 2008-04-05  4:39 UTC (permalink / raw)


Adam Beneschan:

 > When I read this and was thinking randomly about Ada's string
 > handling, I got to wondering why Bounded_Strings was defined as a
 > generic, rather than declaring a discriminated type with the maximum
 > length as the discriminant.

Do you mean something like that ?

------------------------------------------------------------------------------
--  File:           BorString.ads
--  Description:    Variable-size, bounded strings as in early Borland Pascals
--                      Essentially for quick portability purposes.
--  Date / Version: 14-May-2001 ; 4-May-2000
--  Author:         Gautier de Montmollin
--  Portability:    Full: pure Ada 83. Nearest Ada 95+ package: the
--                  generic Ada.Strings.Bounded .
------------------------------------------------------------------------------

package BorStrings is

   type BorString( maxlength: positive ) is private;

   -- Idea: you can convert to string for _functional_ manipulations
   function To_String( b:BorString ) return String;
   -- ... then, put the result in a BorString if needed
   procedure Put( b : in out BorString; c: Character );
   procedure Put( b : in out BorString; s: String );
   procedure Put( bd: in out BorString; bs: BorString );
   -- Note: with the "&" concatenators defined below, you can do it
   -- straigthforward !

   -- * Procedures and functions that are in Turbo Pascal and later:
   --     Concat   Copy   Delete   Insert   Length   Pos
   -- * We add RPos for searching a string from the _right_

   --        Concat: use the "&" operator instead! NB: TP has "+"
   function  Copy(b: BorString; index: Integer; count: Integer) return String;
   procedure Delete( b: in out BorString; index: Positive; count: Positive);
   procedure Insert( source: String; b: in out BorString; index: Integer);
   procedure Insert( source: BorString; b: in out BorString; index: Integer);
   function  Length( b: BorString ) return Natural;
   function  Pos( substr: String; b: BorString) return Natural;
   function  RPos( substr: String; b: BorString) return Natural;

   -- "&" operators returning a BorString of _same_ maxlength as the input
   -- so you can write  b:= b & " "  or b:= "[" & b & "]" !

   function  "&" ( c: Character; b: BorString) return BorString;
   function  "&" ( s: String; b: BorString) return BorString;
   function  "&" ( b: BorString; c: Character) return BorString;
   function  "&" ( b: BorString; s: String) return BorString;

   -- same, returning strings (experimental: can cause ambiguities)

   function  "&" ( c: Character; b: BorString) return String;
   function  "&" ( s: String; b: BorString) return String;
   function  "&" ( b: BorString; c: Character) return String;
   function  "&" ( b: BorString; s: String) return String;

   function Eq ( b1,b2: BorString ) return Boolean;
   function Eq ( b1: BorString; s2: String ) return Boolean;

   string_overflow: exception;

   pragma Inline(To_String);

private
   type BorString( maxlength: positive ) is record
     length: Natural:= 0;
     s: String( 1..maxlength );
   end record;
   -- NB: length allows longer strings than the "s[0]" in T/B-Pascal

end BorStrings;

______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[relevance 10%]

* Re: Ada.Bounded_Strings
  @ 2008-04-05  1:46  4%             ` Adam Beneschan
  2008-04-05  4:55  0%               ` Ada.Bounded_Strings Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Adam Beneschan @ 2008-04-05  1:46 UTC (permalink / raw)


On Apr 4, 4:35 pm, Robert A Duff <bobd...@shell01.TheWorld.com> wrote:
> Adam Beneschan <a...@irvine.com> writes:
> > The disadvantage of this approach was given as this: "[P]redefined
> > assignment and equality for discriminated Bounded_String do not have
> > the desired behavior.  Assignment makes sense when the maximum lengths
> > of source and target are different, as long as the source's current
> > length is no greater than the target's maximum length, yet predefined
> > ":=" would raise Constraint_Error on the discriminant mismatch".
>
> > The reason this doesn't make sense to me is, how does the generic
> > definition solve the problem?
>
> It doesn't, but it does cause the problem to be prevented statically,
> rather than via an exception at run time.

Right.  But even in the discriminant case, the compiler would usually
know statically that the assignment would necessarily raise an
exception.  (I'm assuming the discriminant would be constant in the
vast majority of cases.)  The compilers I'm familiar with would
display that fact at compile time.  Our compiler also has an option to
reject programs that will necessarily fail a predefined check such as
this.


> As far as I know, there is no way to actually solve the problem in Ada
> -- that is, allow all the assignments that make sense, and no others.

Not in a way that allows you to put the two characters := in the
statement.  But  in the discriminant case, you can still define your
own assignment *procedure*, which is almost as good.  I know, it
doesn't help with initializers.


> I must admit, that generic seems awfully heavy.  Part of the rationale
> (rationalization?) was that you can just pick some reasonable max
> length, and instantiate the thing once, and use it all over your
> program.

Again, this doesn't sound reasonable in the context of the sort of
"business applications" that I used to work on in COBOL.  For other
types of applications, it's probably OK, or Ada.Strings.Unbounded may
be best.  The reason I'm even thinking about all this is that I had
been hoping for a number of years now that Ada would be able to make
inroads into "business" applications and maybe be seen as an
alternative to COBOL, and I'm a bit disappointed that, AFAIK, nothing
or very little has happened in that arena.  Not that I think
Ada.Strings.Bounded is a major reason for this, or that providing a
better string-handling facility would help at all.  (shrug)

                                -- Adam




^ permalink raw reply	[relevance 4%]

* Re: Ada.Strings.Bounded
  @ 2008-04-04 21:15 12%           ` Adam Beneschan
  2008-04-05  4:39 10%             ` Ada.Strings.Bounded Gautier
    1 sibling, 1 reply; 200+ results
From: Adam Beneschan @ 2008-04-04 21:15 UTC (permalink / raw)


On Apr 4, 2:09 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Apr 4, 9:10 am, Pascal Obry <pas...@obry.net> wrote:
>
> > > Sorting out string handling out would be nice, too.
>
> > Probably something to do in this area I agree.
>
> OK, this is *really* beating a dead horse, but...
>
> When I read this and was thinking randomly about Ada's string
> handling, I got to wondering why Bounded_Strings was defined as a
> generic

I got sloppy with the names, of course.  The package name is
Ada.Strings.Bounded, and the generic I'm referring to is the nested
generic package Generic_Bounded_Length.  Please imagine the
appropriate substitutions in the rest of my post.  Hopefully you can
all tell what I meant.  I guess that tells you how often I use this.

                                 -- Adam



^ permalink raw reply	[relevance 12%]

* Re: Private type definition must be definite : but why ?
  @ 2008-03-03 16:29  4%   ` Adam Beneschan
  0 siblings, 0 replies; 200+ results
From: Adam Beneschan @ 2008-03-03 16:29 UTC (permalink / raw)


On Mar 1, 4:37 pm, "Hibou57 (Yannick Duchêne)"
<yannick_duch...@yahoo.fr> wrote:
> Oops, sorry.... I was to much speedy to see a trouble here.
>
> I just have to use an unknown discriminant part (beceause it is
> private), thus just have to do
>
> > package Xxx
> >   type Data_Row_Type(<>) is private;
> >   ...
> > private
> >    type Data_Row_Type is new String;
> >   ...
> > end Xxx;
>
> And it works, and every body's happy... me first :D
>
> Well, to be honest, I still do not understand why the user have to
> know there is are unknow discriminants somewhere..... the user does
> not need to know.

The "user" has to know that there are unknown *constraints* (which
could be discriminants, or could, as in this case, be array
constraints), so that the user knows that you can't declare a variable
(or other object) of that type without adding constraints.  This is
illegal:

    X : String;

since you have to put array constraints on it.  And if your program
looks like this:

    package Xxx is
        type Data_Row_Type is private;
    private
        DO NOT LOOK IN HERE
    end Xxx;

    with Xxx;
    package Yyy is
        Z : Xxx.Data_Row_Type;
    end Yyy;

If Data_Row_Type could be a "new String", you wouldn't be able to tell
that Z is illegal without looking in the private part of Xxx, and
you're not allowed to look at that.  That's what Bob referred to as
"breaking privacy".

In this case:

    package Xxx is
        type Data_Row_Type(<>) is private;
    private
        DO NOT LOOK IN HERE
    end Xxx;

    with Xxx;
    package Yyy is
        Z : Xxx.Data_Row_Type;  -- ILLEGAL
    end Yyy;

Now Z is illegal, and the "user" can tell that without having to look
in the private part of Xxx.  That would make it OK for Data_Row_Type
to be declared as a String.

When you declare a private type, you'll need to ask: Does your design
require that users of the package declare objects of that type?  If
the answer is "no", then you should put (<>) on the declaration so
that you can make the private type be anything you want.

P.S. If you really need Data_Row_Type to be a string and you need your
users to be able to declare objects of the type, consider
Ada.Strings.Bounded or Ada.Strings.Unbounded.

                                   -- Adam








^ permalink raw reply	[relevance 4%]

* Re: Text Processing in Ada 95
  @ 2007-02-22  2:45  5% ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2007-02-22  2:45 UTC (permalink / raw)


Rob Norris wrote:
> 
> Currently I'm using text_io which means I have to copy the whole thing into memory, insert the line
> then over write the file with new contents. direct_io is not an option (varing string lengths)

Is there an upper limit to the string lengths (other than 
Positive'Last)? If so, you could use Ada.Strings.Bounded and Direct_IO.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail
18



^ permalink raw reply	[relevance 5%]

* Re: Strings and errors... (gnat)
  @ 2006-11-29 18:10  7%     ` Ludovic Brenta
  0 siblings, 0 replies; 200+ results
From: Ludovic Brenta @ 2006-11-29 18:10 UTC (permalink / raw)


tr00per writes:
> Robert A Duff napisal(a):
>> You can't assign a shorter string into a longer one -- the lengths have
>> to match.  You could do:
>>
>>     tmp: String := buf(13..26);
>>
>> or
>>
>>     tmp: constant String := buf(13..26);
>>
>> and it will take the bounds for tmp from buf(13..26).
>>
>> Or, you could use Unbounded_Strings.
>>
>> - Bob
>
> Actual length of the string is dependend on other data, range here is
> for example, so these declarations aren't solution for me, but thanks
> anyway. Maybe there is a ready-to-use function for splitting the string
> by template, so I don't have to reinvent the wheel?
> I have input in format String:String:String. I want to get rid of these
> colons and get three seperate strings.

Robert's advice still holds:

1) the bounds of a String can be dynamic, so you can also say
   tmp : constant String := buf (A .. B); -- A and B computed from input

2) You can use Ada.Strings.Unbounded.

Now for my own advice:

1) Look at Ada.Strings.Fixed.Find_Token.  It will help you find the
   colons.

2) Look at Ada.Strings.Bounded; it is more efficient than
   Unbounded_Strings, but you have know the maximum length in advance.

3) If you are writing a subprogram that splits a given string into 3
   strings of unknown length, you have basically 4 options:

   a) return 3 access values to dynamically allocated strings
   b) return 3 unbounded strings
   c) return 3 bounded strings
   d) return 3 fixed strings and 3 Last values, like
      Ada.Text_IO.Get_Line does.

But simply returning 3 fixed strings will not work.

-- 
Ludovic Brenta.



^ permalink raw reply	[relevance 7%]

* Re: STRING length
  2006-11-15  0:44  0%   ` markww
@ 2006-11-15  1:09  0%     ` markww
  0 siblings, 0 replies; 200+ results
From: markww @ 2006-11-15  1:09 UTC (permalink / raw)


Actually please disregard the previous post, I found I needed to with
and use:

    Ada.Text_IO.Unbounded_IO

So.. finally one compilation error remains, the actual call to my
function:

    begin

        Add_Record("Mark", "555-555-5555", "123 main street");

    end LinkList;

the error is:

    expected private type "Ada.Strings.Unbounded.Unbounded_String"

what does that mean? The problem is with calling the procedure, if I
comment the call out compilation is successful. The procedure looks
like:

    procedure Add_Record(strName : in UNBOUNDED_STRING;
                                      strPhone : in UNBOUNDED_STRING;
                                      strAddress : in UNBOUNDED_STRING)
is
       Temp : CHAR_REC_POINT;
   begin
	Put(strName);
	New_Line;
	Put(strPhone);
	New_Line;
	Put(strAddress);
	New_Line;
    end Add_Record;

I guess the compiler doesn't interpret a literal string as an
unbounded_string?

Thanks,
Mark


On Nov 14, 7:44 pm, "markww" <mar...@gmail.com> wrote:
> Thanks Georg, that looks to be exactly what I need. I do have a problem
> '#including', or, 'withing' rather unbounded string.
> Now the head of my source file looks like:
>
>     with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded;
>     use Ada.Text_IO, Ada.Integer_Text_IO;
>
> which is alright but as soon as I try:
>
>     use Ada.Strings.Unbounded;
>
> the compiler gives me a bunch of errors, it seems to conflict with
> Text_IO / Integer_Text_IO? Seems like all my previous calls to Put()
> now became invalid. I'm not familiar with Ada but with C++ and
> understand namespace collisions, is the same thing going on here?
>
> Thanks
>
> On Nov 14, 5:24 pm, Georg Bauhaus <bauh...@futureapps.de> wrote:
>
>
>
> > On Tue, 2006-11-14 at 14:51 -0800, markww wrote:
> > > Hi,
>
> > > How does one use a variable length string in ada?You use variable length strings in Ada by declaring them
> > to be of type UNBOUNDED_STRING which is defined in
> > Ada.Strings.Unbounded.
>
> > type MY_RECORD is
> >   record
> >     Name: UNBOUNDED_STRING;
> >     Phone: UNBOUNDED_STRING;
> >     Address: UNBOUNDED_STRING;
> >   end record;
>
> > Given that Phone is likely to be limited in length, you
> > could consider declaring the Phone component to be of
> > type BOUNDED_STRING, which is a string type with a maximum length.
> > Unlike STRING, objects of this type can have any number
> > of characters up to the maximum. See Ada.Strings.Bounded.
>
> > Yet another use of strings is in nested scopes: If you need
> > a string in just one place, e.g. temporarily, you can use
> > a plain STRING as in
>
> >   declare
> >     temp: constant STRING := some_string_returning_func(...);
> >   begin
> >     -- use temp
> >   end;
>
> > The point here is that the `temp` string variable takes
> > its bound from the initialization. You can also make it a
> > variable, if you need to write to string components.
>
> > Seehttp://en.wikibooks.org/wiki/Ada_Programming/Strings
> 
> > -- Georg- Hide quoted text -- Show quoted text -




^ permalink raw reply	[relevance 0%]

* Re: STRING length
  2006-11-14 22:24  6% ` Georg Bauhaus
@ 2006-11-15  0:44  0%   ` markww
  2006-11-15  1:09  0%     ` markww
  0 siblings, 1 reply; 200+ results
From: markww @ 2006-11-15  0:44 UTC (permalink / raw)


Thanks Georg, that looks to be exactly what I need. I do have a problem
'#including', or, 'withing' rather unbounded string.
Now the head of my source file looks like:

    with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded;
    use Ada.Text_IO, Ada.Integer_Text_IO;

which is alright but as soon as I try:

    use Ada.Strings.Unbounded;

the compiler gives me a bunch of errors, it seems to conflict with
Text_IO / Integer_Text_IO? Seems like all my previous calls to Put()
now became invalid. I'm not familiar with Ada but with C++ and
understand namespace collisions, is the same thing going on here?

Thanks


On Nov 14, 5:24 pm, Georg Bauhaus <bauh...@futureapps.de> wrote:
> On Tue, 2006-11-14 at 14:51 -0800, markww wrote:
> > Hi,
>
> > How does one use a variable length string in ada?You use variable length strings in Ada by declaring them
> to be of type UNBOUNDED_STRING which is defined in
> Ada.Strings.Unbounded.
>
> type MY_RECORD is
>   record
>     Name: UNBOUNDED_STRING;
>     Phone: UNBOUNDED_STRING;
>     Address: UNBOUNDED_STRING;
>   end record;
>
> Given that Phone is likely to be limited in length, you
> could consider declaring the Phone component to be of
> type BOUNDED_STRING, which is a string type with a maximum length.
> Unlike STRING, objects of this type can have any number
> of characters up to the maximum. See Ada.Strings.Bounded.
>
> Yet another use of strings is in nested scopes: If you need
> a string in just one place, e.g. temporarily, you can use
> a plain STRING as in
>
>   declare
>     temp: constant STRING := some_string_returning_func(...);
>   begin
>     -- use temp
>   end;
>
> The point here is that the `temp` string variable takes
> its bound from the initialization. You can also make it a
> variable, if you need to write to string components.
>
> Seehttp://en.wikibooks.org/wiki/Ada_Programming/Strings
> 
> -- Georg




^ permalink raw reply	[relevance 0%]

* Re: STRING length
  @ 2006-11-14 22:24  6% ` Georg Bauhaus
  2006-11-15  0:44  0%   ` markww
  0 siblings, 1 reply; 200+ results
From: Georg Bauhaus @ 2006-11-14 22:24 UTC (permalink / raw)


On Tue, 2006-11-14 at 14:51 -0800, markww wrote:
> Hi,
> 
> How does one use a variable length string in ada?

You use variable length strings in Ada by declaring them
to be of type UNBOUNDED_STRING which is defined in
Ada.Strings.Unbounded. 

type MY_RECORD is
  record
    Name: UNBOUNDED_STRING;
    Phone: UNBOUNDED_STRING;
    Address: UNBOUNDED_STRING;
  end record;

Given that Phone is likely to be limited in length, you
could consider declaring the Phone component to be of
type BOUNDED_STRING, which is a string type with a maximum length.
Unlike STRING, objects of this type can have any number
of characters up to the maximum. See Ada.Strings.Bounded.

Yet another use of strings is in nested scopes: If you need
a string in just one place, e.g. temporarily, you can use
a plain STRING as in

  declare
    temp: constant STRING := some_string_returning_func(...);
  begin
    -- use temp
  end;

The point here is that the `temp` string variable takes
its bound from the initialization. You can also make it a
variable, if you need to write to string components.

See
http://en.wikibooks.org/wiki/Ada_Programming/Strings


-- Georg 





^ permalink raw reply	[relevance 6%]

* Re: Is there an end of string like in C
       [not found]     <1151691630.276880.203280@75g2000cwc.googlegroups.com>
@ 2006-06-30 20:12  5% ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2006-06-30 20:12 UTC (permalink / raw)


Chris L wrote:
> In C, there is an end of string character ('\0'). Is there one in Ada?
> Can you give me code that checks for it in an array?

In Ada, a string type is a one-dimensional array type with components of 
a character type. You can define your own character types and your own 
string types. If you want to define your own end-of-string character and 
a library of operations that know about that character you certainly can.

The predefined type Character is a character type. The predefined type 
String is a string type. Its definition is

type String is array (Positive range <>) of Character;
pragma Pack (String);

The definitions of Character and String do not define an end-of-String 
Character or any operations that treat a Character as such.

The C approach is referred to in Ada as a bounded string; the logical 
value can vary in length from zero to some maximum number of characters. 
You can also consider an unbounded string, in which there is no upper 
limit to the length (except as imposed by available storage). You might 
want to look at Ada.Strings.Bounded and Ada.Strings.Unbounded for the 
Ada Way to do this sort of thing.

One advantage of the Ada Way is that all characters can be elements of a 
string.

This is all pretty basic and should be covered by any text or tutorial, 
which you should have worked through before asking questions such as 
this. You can find on-line texts and tutorials at www.adapower.com and 
www.adaworld.com.

-- 
Jeff Carter
"The time has come to act, and act fast. I'm leaving."
Blazing Saddles
36



^ permalink raw reply	[relevance 5%]

* Re: ada and pl/sql
  2006-03-27 20:05  5% ada and pl/sql Jason King
  2006-03-27 20:28  0% ` Georg Bauhaus
@ 2006-03-27 21:07  0% ` Björn Persson
  1 sibling, 0 replies; 200+ results
From: Björn Persson @ 2006-03-27 21:07 UTC (permalink / raw)


Jason King wrote:
> declare
>    v1 varchar2(10) := 'Hello';
>    v2 varchar2(10) := 'World';
>    v3 varchar2(30);
> begin
>    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
>                            -- no error here since 'Hello World'
>                            -- fits.
>    dbms_output.put_line(v3) ; -- prints "Hello World"
[...]
> ada.strings.bounded and 
> ada.strings.unbounded are issues because assignment (:=) doesn't work 
> for them and concatenation is method not an operator.

Assignment and concatenation work just fine. Here's your example in Ada:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;

procedure Unbounded_Demo is
    String_1 : Unbounded_String := To_Unbounded_String("Hello");
    String_2 : Unbounded_String := To_Unbounded_String("World");
    String_3 : Unbounded_String;
begin
    String_3 := String_1 & ' ' & String_2;
    Ada.Text_IO.Unbounded_IO.Put_Line(String_3);
end Unbounded_Demo;

(Ada.Text_IO.Unbounded_IO is new in Ada 2005, so it's only present in 
the newest libraries.)

> As far as I can 
> tell I can't overload the assignment operator or the || operator.

That's right. Instead of overloadable assignment, Ada has controlled 
types. "||" isn't an operator in Ada; the string concatenation operator 
is "&", and that one is overloadable.

> Other than creating a new language is there some way to make a 
> varchar2-like first-class datatype that has its own operators?

It's perfectly possible to create such a type in pure Ada, but you don't 
need to, because it's already there in the standard library. Bounded or 
unbounded strings are what you want.

I have actually written a string handling package of my own. I got sick 
of the endless character encoding bugs, so I created an unbounded string 
type where each string object keeps track of its own encoding. I call it 
EAstrings � encoding-aware strings.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



^ permalink raw reply	[relevance 0%]

* Re: ada and pl/sql
  2006-03-27 20:05  5% ada and pl/sql Jason King
@ 2006-03-27 20:28  0% ` Georg Bauhaus
  2006-03-27 21:07  0% ` Björn Persson
  1 sibling, 0 replies; 200+ results
From: Georg Bauhaus @ 2006-03-27 20:28 UTC (permalink / raw)


Jason King wrote:

> Ada string doesn't work because it raises errors for assignments of
> shorter as well as longer strings.  ada.strings.bounded and
> ada.strings.unbounded are issues because assignment (:=) doesn't work
> for them and concatenation is method not an operator.  As far as I can
> tell I can't overload the assignment operator or the || operator.
> Other than creating a new language is there some way to make a
> varchar2-like first-class datatype that has its own operators?
 
There seems to have been some misinformation somewhere, try
this:

with Ada.Strings.Unbounded;
with Ada.Text_IO;

procedure v is

   use Ada.Strings.Unbounded, Ada;

   x: Unbounded_String := Null_Unbounded_String;

begin
   x := x & "Hello";
   x := x & "World";
   Text_IO.put_line(to_string(x));
end v;





^ permalink raw reply	[relevance 0%]

* ada and pl/sql
@ 2006-03-27 20:05  5% Jason King
  2006-03-27 20:28  0% ` Georg Bauhaus
  2006-03-27 21:07  0% ` Björn Persson
  0 siblings, 2 replies; 200+ results
From: Jason King @ 2006-03-27 20:05 UTC (permalink / raw)


I'm a long-term pl/sql developer who would like to have a general 
purpose programming language that works a lot like what I'm used to. 
Hence I've been looking at Ada.
There are (from the pl/sql perspective) three significant differences:
1)  Transparent shifting from pl/sql to sql
     FOR x IN (SELECT user_name FROM all_users ) LOOP
         -- do something
     END LOOP ; -- creates a cursor and x.user_name is valid inside the 

                --loop
2)  pl/sql is very forgiving about doing "automatic" conversions
     x number := "1" + 2; -- assigns 3 to x it doesn't raise an error.
3)  The most commonly used string type is varchar2 with usage examples 
   below:
    v varchar2(50);  -- declare a varchar2, max length 50
    v varchar2(50) := 'short string';  -- assign a value, literal <50
                                       -- does not raise an error.
    v varchar2(10) := '12345678901' ;  -- raises value_error
                                       -- literal > max
declare
    v1 varchar2(10) := 'Hello';
    v2 varchar2(10) := 'World';
    v3 varchar2(30);
begin
    v3 := v1 || ' ' || v2 ; -- || is string concat operator.
                            -- no error here since 'Hello World'
                            -- fits.
    dbms_output.put_line(v3) ; -- prints "Hello World"

Issue 1 is true for all languages so I can just deal with it.
Issue 2 I often code around on the pl/sql as its automatic conversions 
aren't always what I want.
Issue 3 is a killer.
Ada string doesn't work because it raises errors for assignments of 
shorter as well as longer strings.  ada.strings.bounded and 
ada.strings.unbounded are issues because assignment (:=) doesn't work 
for them and concatenation is method not an operator.  As far as I can 
tell I can't overload the assignment operator or the || operator.
Other than creating a new language is there some way to make a 
varchar2-like first-class datatype that has its own operators?





^ permalink raw reply	[relevance 5%]

* Re: Silly question about strings (was: Filenames in Ada)
  2005-11-24  3:21  6%   ` Silly question about strings (was: Filenames in Ada) Steve
@ 2005-11-24  4:58  0%     ` Larry Kilgallen
  0 siblings, 0 replies; 200+ results
From: Larry Kilgallen @ 2005-11-24  4:58 UTC (permalink / raw)


In article <oNmdneZx9ePFrBjenZ2dnUVZ_t2dnZ2d@comcast.com>, "Steve" <nospam_steved94@comcast.net> writes:
> This may be a silly question, but why aren't the character dependent
> packages generic?
>
> It seems odd to have separate packages:
>
>   Ada.Strings.Fixed;
>   Ada.Strings.Wide_Fixed;
>   Ada.Strings.Bounded;
>   Ada.Strings.Wide_Bounded;
>   Ada.Strings.Unbounded;
>   Ada.Strings.Wide_Unbounded;
>   Ada.Text_IO;
>   Ada.Wide_Text_IO;
>
> Instead of generic packages that use the character type as a parameter, with
> predefined instatiations for character and wide_character similar to what is
> done with numerics.  Perhaps something along the lines of:
>
>   package Ada.Strings.Fixed is new Ada.Strings.String_Base( Character );
>   package Ada.Strings.Wide_Fixed is new Ada.Strings.String_Base(
> Wide_Character );
>
> and so on...
>
> It seems like this would eliminate issues with different character sets, and
> avoid the need for a language revision when a 64 bit (or 128 bit) version of
> Unicode arrives.

I would expect those string packages (and especially the string IO
packages) would use operating system facilities in some implementations.
The underlying operating system calls might not be symmetric at all.
The bodies might not even be written in Ada.



^ permalink raw reply	[relevance 0%]

* Silly question about strings (was: Filenames in Ada)
  @ 2005-11-24  3:21  6%   ` Steve
  2005-11-24  4:58  0%     ` Larry Kilgallen
  0 siblings, 1 reply; 200+ results
From: Steve @ 2005-11-24  3:21 UTC (permalink / raw)


This may be a silly question, but why aren't the character dependent 
packages generic?

It seems odd to have separate packages:

  Ada.Strings.Fixed;
  Ada.Strings.Wide_Fixed;
  Ada.Strings.Bounded;
  Ada.Strings.Wide_Bounded;
  Ada.Strings.Unbounded;
  Ada.Strings.Wide_Unbounded;
  Ada.Text_IO;
  Ada.Wide_Text_IO;

Instead of generic packages that use the character type as a parameter, with 
predefined instatiations for character and wide_character similar to what is 
done with numerics.  Perhaps something along the lines of:

  package Ada.Strings.Fixed is new Ada.Strings.String_Base( Character );
  package Ada.Strings.Wide_Fixed is new Ada.Strings.String_Base( 
Wide_Character );

and so on...

It seems like this would eliminate issues with different character sets, and 
avoid the need for a language revision when a 64 bit (or 128 bit) version of 
Unicode arrives.

Steve
(The Duck) 





^ permalink raw reply	[relevance 6%]

* Re: Initialize with aggregate?
  2005-11-22 16:57  5%   ` Adam Beneschan
@ 2005-11-22 20:07  0%     ` Robert A Duff
  0 siblings, 0 replies; 200+ results
From: Robert A Duff @ 2005-11-22 20:07 UTC (permalink / raw)


"Adam Beneschan" <adam@irvine.com> writes:

> > Hardwiring Item'Length to 50 isn't a good idea, and it makes the
> > programming harder, because you have to carefully avoid the junk
> > at the end.
> 
> I don't see how you can make a blanket statement like this.

You're right.  Perhaps I should say, "Hardwiring Item'Length to 50 is
_almost_never_ a good idea."  The way I showed is fine if the string
doesn't change its length.  If it does, Strings.Unbounded is most likely
what you want.  In the unlikely event that the length changes, and "50"
is an appropriate upper-bound, Strings.Bounded is probably best, as you
mention below.

A blank-padded string is unlikely to be a good idea.

>...If you
> code it the way you've shown, you can't change "len" in a node once
> you've allocated it.  But sometimes changing "item" and "len" in an
> existing node to change the length of the string, without changing the
> other fields in the node, is what you want to do, so there are cases
> where the original poster's implementation is more appropriate than
> using a discriminant record.  (Using Ada.Strings.Bounded may make
> programming easier still, but you still have to hardwire a maximum
> length.)

- Bob



^ permalink raw reply	[relevance 0%]

* Re: Initialize with aggregate?
  @ 2005-11-22 16:57  5%   ` Adam Beneschan
  2005-11-22 20:07  0%     ` Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Adam Beneschan @ 2005-11-22 16:57 UTC (permalink / raw)


Robert A Duff wrote:
> ejijott@gmail.com writes:
>
> > Hi there!
> >
> > Regarding the code below, what syntax do I use to initialize tempstore
> > with an aggregate?
> > [code]
> > .
> > .
> > .
> >     type node;
> >     type storage is access node;
> >     type node is
> >         record
> >             next:  storage;       -- Pekare till nästa nod.
> >             item:  string(1..50); -- En textsträng
> >             len:   integer :=-1;  -- Längden på strängen.
> >             count: integer := 0;  -- Antalet förekomster av strängen
> >         end record;
> > .
> > .
> > .
> >         tempstore:=new Node;
> >         tempstore.item(1 .. Val'length):=Val;
> >         tempstore.len:=Val'length;
> >         tempstore.count:=1;
> >         if S /= null then
> >             tempstore.next:=S;
> >         end if;
> >         S:=tempstore;
> > [/code]
>
> How about something like this:
>
>     type node;
>     type storage is access node;
>     type node(len: natural) is
>         record
>             next:  storage;       -- Pekare till nästa nod.
>             item:  string(1..len); -- En textsträng
>             count: integer := 0;  -- Antalet förekomster av strängen
>         end record;
>
>     tempstore:=new Node'(
>             len => val'length,
>             next => S,
>             item => val,
>             count => 1);
>     S:=tempstore;
>
> Hardwiring Item'Length to 50 isn't a good idea, and it makes the
> programming harder, because you have to carefully avoid the junk
> at the end.

I don't see how you can make a blanket statement like this.  If you
code it the way you've shown, you can't change "len" in a node once
you've allocated it.  But sometimes changing "item" and "len" in an
existing node to change the length of the string, without changing the
other fields in the node, is what you want to do, so there are cases
where the original poster's implementation is more appropriate than
using a discriminant record.  (Using Ada.Strings.Bounded may make
programming easier still, but you still have to hardwire a maximum
length.)

                                    -- Adam




^ permalink raw reply	[relevance 5%]

* Re: Dinamic String
  @ 2005-10-17 19:23  5%   ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2005-10-17 19:23 UTC (permalink / raw)


Martin Dowie wrote:

> Check out package "Ada.Strings.Unbounded", RM  A.4.5

Or Ada.Strings.Bounded (ARM A.4.4), depending on your needs.

-- 
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
13



^ permalink raw reply	[relevance 5%]

* [Announce] AVR-Ada V0.3 released
@ 2005-08-03 10:24  2% rolf.ebert_nospam_
  0 siblings, 0 replies; 200+ results
From: rolf.ebert_nospam_ @ 2005-08-03 10:24 UTC (permalink / raw)


We are proud to announce a new release of AVR-Ada, one of the first GCC
based Ada compilers targeting 8-bit microcontrolers.

You can get the project description and some documentation at

     avr-ada.sourceforge.net

The SF development pages with the download section are at

     www.sourceforge.net/projects/avr-ada


AVR-Ada is available in source form only.  Binary packages of the cross
compiler hosted on Linux and Windows are expected to appear with future
releases of cdk4avr (cdk4avr.sourceforge.net) and WinAVR
(winavr.sourceforge.net).

Feel free to join the mailing list at

     http://lists.sourceforge.net/mailman/listinfo/avr-ada-devel.

It has quite low traffic.


Please use SF's bug reporting system for guiding future development of
AVR-Ada.


Status
======

The goal of the AVR-Ada project is to make the gcc based Ada compiler
GNAT available for the AVR microcontrollers.

More specifically the project provides

 -  a GNAT compiler based on the existing AVR and Ada support in gcc
 -  a minimalistic Ada runtime system
 -  a useful AVR specific support library

The current distribution of AVR-Ada is V0.3. It is based on gcc-3.4.4.
In the AVR-Ada project we never had problems with the Ada compiler
itself. It is quite stable.

The Ada run time system (RTS) on the other hand is still not even a
*run* time system.  It is more a compile time system :-). All files in
the RTS are only needed at compile time.  As a consequence we don't
have support for exceptions nor for tasking (multithreading).

There is a bit of AVR specific support.  Some type and interface
definitions, timing routines, eeprom access, UART, and most
importantly the necessary definitions for most AVR parts.

Some sample programs in the apps/ directory show how to use the
compiler and the library.  This includes the tutorial program from an
older avr-libc distribution and some of Peter Fleury's example programs
(http://homepage.sunrise.ch/mysunrise/peterfleury/avr-software.html)
translated to Ada.

The documentation is still low and consists only of the pages at
avr-ada.sourceforge.net.  A copy of the pages is in the directory
AVR-Ada/web/ for offline reading.  Feel free to ask any question on the
mailing list.


News
====

0.3 (2005-08-03)
----------------

The part description spec files are completely new.  The Ada specs are
now generated directly from Atmel's XML part description files of AVR
Studio 4.11 build 406 SP 2.  In previous versions they were derived
from the C header files of avr-libc.

We changed the syntax for accessing single bits from bit numbering to
masks in AVR.IO.  Simple names in the part description specs now
contain bit masks, the pin number is still available with the name
xxx_Bit.  E.g.:

    --  Port D Data Register bit 3
    PORTD3_Bit               : constant Bit_Number := 3;
    PORTD3                   : constant Byte       := 16#08#;

The previous Set_IO routines in AVR.IO were renamed to simply Put
omitting the _IO, the Get_IO have become Get.  That is more in the
style of other Ada IO packages like Text_IO.

New packages for string handling and accessing constants in program
space.  They are actually a stripped down version of
Ada.Strings.Bounded.

We build part specific libraries now.  That means that we can provide
specific functionality adapted to a given part.  It is currently used
for the UART and EEPROM access only, though.

The example programs for accessing 1-wire devices and an LCD are not
part of the distribution anymore.  They are only available via CVS.
There is also starting support for the atmega169 based AVR Butterfly in
the CVS repository (UART, LCD, and dataflash).


0.2 (2004-10-28)
----------------

We modified the compiler patches to fit cleanly to gcc-3.4.3.  They
probably also fit in previous gcc-3.4.x releases; I never tried.

The "freestanding" patch is now considerably shorter since part of what
it does (avoid some code in the binder file) is now provided directly
in gcc.  The corresponding binder options was previously called
"standalone", but that expression is used elsewhere in GNAT.

You can now use "Library Projects" with AVR-Ada.  I.e. you can
have gpr files with "Library_Name", etc.  The only permitted value for
"Library_Kind" is "static".  This feature is used for the Avr library.

gcc-3.4.3 now fully supports -fdata-sections (PR14064) and
-ffunction-sections for AVR targets in C and Ada.  This
particularily useful for embedded systems where code and static data
must not be wasted.




^ permalink raw reply	[relevance 2%]

* XML Strings in Ada
@ 2004-12-08 16:46  6% Robert C. Leif
  0 siblings, 0 replies; 200+ results
From: Robert C. Leif @ 2004-12-08 16:46 UTC (permalink / raw)
  To: comp.lang.ada

   If any one wishes to see and use my code for noncommercial purposes,
please email me.  The packages are not yet ready for publication; however, I
have used them on internal projects.  Since Packages that are part of the
Ada standard are not allowed to have user defined child libraries, I took a
library generic and made a new generic from it.  The Pattern_Pkg Should be a
subset of that in XML with new meaningful abbreviations. 
      Parenthetically, the use of html formatting would assist in formatting
listings for Comp.Lang.Ada.  The sources of my Ada_Utilities will be made
available under one of the new licenses that are derived or in the spirit of
my Software Developers Cooperative License.
      Bob Leif
       
      Briefly the beigining of the package specification contains:
      with Ada.Strings.Bounded;
      with Ada.Strings.Unbounded;
      with Pattern_Pkg; --not yet completed. 
      with Ada.Strings;
      with Character_Sets;
      with Ada.Characters.Latin_1;
      with Strings8_16_32_Pkg;
      generic
         Max_Bd_Length : Positive;
         Min_Bd_Length : Positive:= 1;
         Character_Set:Character_Sets.Character_Set_Type:=
Character_Sets.Latin_1_Char_Set;
         Pattern:Pattern_Pkg.Pattern_Bd_Type := Pattern_Pkg.Null_Pattern_Bd;
         --Had to create to equal Ada.Characters.Latin_1. 
        --This has to be replaced by the proper Unicode names
         --or, at least, the names specified in The Ada95 XML Library 
      --by Emmanuel Briot Unicode child libraries
         --http://libre.act-europe.fr/xmlada/main.html
      package Generic_Bd_W_Char_Sets is
         Pkg_Name : constant String := "Generic_Bd_W_Char_Sets";
         Monitor : Boolean := True;
         --Makes visible to all of the instantiations.
         --***********************Table of
Contents--*************************
         package Unbounded renames Ada.Strings.Unbounded;
         subtype String_Unbd is Ada.Strings.Unbounded.Unbounded_String;
         subtype Truncation is Ada.Strings.Truncation;
         Error : Ada.Strings.Truncation renames Ada.Strings.Error;
         subtype Trim_End is Ada.Strings.Trim_End;
         Left : Trim_End renames Ada.Strings.Left;
         Right : Trim_End renames Ada.Strings.Right;
         Both : Trim_End renames Ada.Strings.Both;
      
         subtype Character_Set_Type is Character_Sets.Character_Set_Type;
      
         subtype Case_Type is Character_Sets.Case_Type;
         Upper_Case : Case_Type renames Character_Sets.Upper_Case;
         Lower_Case : Case_Type renames Character_Sets.Lower_Case;
         Both_Cases : Case_Type renames Character_Sets.Both_Cases;
         Space : Character renames Ada.Characters.Latin_1.Space;
      
         subtype Pattern_Bd_Type is Pattern_Pkg.Pattern_Bd_Type;
         Null_Pattern_Bd: Pattern_Bd_Type renames
Pattern_Pkg.Null_Pattern_Bd;
         Subtype Character16_Set_Type is
Strings8_16_32_Pkg.Character16_Set_Type;
         Latin_1_16_Char_Set:Character16_Set_Type
      renames Strings8_16_32_Pkg.Latin_1_16_Char_Set;
         --**************End Table of Contents--*************************
         package Generic_Bd_Strings is new
            Ada.Strings.Bounded.Generic_Bounded_Length(Max =>
Max_Bd_Length);
         use Generic_Bd_Strings;   
 
----------------------------------------------------------------------
         subtype Generic_Bd_Type is Generic_Bd_Strings.Bounded_String;  --NO
         --DO NOT USE FOR Instatiations!
         Null_Generic_Bd : Generic_Bd_Type :=
Generic_Bd_Strings.Null_Bounded_String; --NO
         --DO NOT USE FOR Instatiations!
         subtype Length_Range_Type is Generic_Bd_Strings.Length_Range;
      
         subtype Non_Member_Sequence_Bd_Type is
Character_Sets.Non_Member_Sequence_Bd_Type;
      
         --********************End Table of
Contents--*************************
         type Generic_Bd_W_Char_Set_Type is tagged private; --record
 
-----------------------------------------------------------------------
         function Null_Generic_Bd_W_Char_Set return
Generic_Bd_W_Char_Set_Type;
         
         ---------------------------------------------------------------
         function Img (
               Generic_Bd_W_Char_Set : Generic_Bd_W_Char_Set_Type )
           return String;
         ---------------------------------------------------------------
         function Img16 (
               Generic_Bd_W_Char_Set :        Generic_Bd_W_Char_Set_Type;
               Not_In_Char           : in     Wide_Character             :=
'?' )
           return Wide_String;
      --Many more functions and procedures
      private
      
         type Generic_Bd_W_Char_Set_Type is tagged
            record
               Generic_Bd_Part    : Generic_Bd_Type    := Null_Generic_Bd;
               Character_Set_Part : Character_Set_Type := Character_Set;
               Min_Bd_Length_Part : Positive           := Min_Bd_Length;
               Pattern_Part       : Pattern_Bd_Type    := Null_Pattern_Bd;
               --This permits the Character_Set to be specified 
      --at instantiation and defaults to Latin_1.
            end record;
      ----------------
      Message: 5
      Date: Tue, 07 Dec 2004 19:41:35 GMT
      From: Bj?rn Persson <spam-away@nowhere.nil>
      Subject: Re: Experiences of XML parser generators for Ada?
      To: comp.lang.ada@ada-france.org
      Message-ID: <PHntd.123697$dP1.439213@newsc.telia.net>
      Content-Type: text/plain; charset=ISO-8859-1; format=flowed
      
      Robert C. Leif wrote:
      
      > I have also created Ada bounded strings that include character sets.
      
      What do you mean with "strings that include character sets"? Do the 
      strings carry information about which character encoding they're
encoded 
      in? In that case I'd be interested in looking at your implementation.
      
      -- 
      Bjvrn Persson                              PGP key A88682FD
                          omb jor ers @sv ge.
                          r o.b n.p son eri nu
      




^ permalink raw reply	[relevance 6%]

* Re: dynamic array as return value?
       [not found]     <cklea4$9eb$1@netnews.hinet.net>
@ 2004-10-14 17:24  4% ` Nick Roberts
  0 siblings, 0 replies; 200+ results
From: Nick Roberts @ 2004-10-14 17:24 UTC (permalink / raw)


bubble wrote:

> In Ada the bounds of an array need not be fixed at compile-time, as they can
> be specified by an object whose
> value is not fixed until run-time. Such an array is known as a dynamic
> array. However, once elaborated, the
> bounds of the dynamic array cannot be changed.

I think this could be put better, to be honest. In Ada, the bounds of an
array /value/ can be dynamic, but the bounds of an /object/ cannot change
dynamically. An 'object' is a variable, including a component of an array
or record value.

Since a function returns an object, the bounds of an array object
returned by a function cannot be changed dynamically. However, the
expression which is evaluated to construct the object which is returned
can have dynamically calculated bounds.

> Unlike many other languages, Ada allows a dynamic array to be returned
> as the result of a function. For example, a function Reverse_String
> can be written which reverses the characters passed to it.
> 
> An implementation of the function Reverse_String is as follows:
> 
> function Reverse_String( Str:in String ) return String is
>     Res : String( Str'Range ); --Dynamic bounds
> begin
>     for I in Str'Range loop
>         Res( Str'First+Str'Last-I ) := Str( I );
>     end loop;
>     return Res;
> end Reverse_String;

When this function executes the 'return' statement, the return expression
(Res) is evaluated, to construct an object (of the type String), and this
object is returned. The bounds are dynamically calculated, but once
calculated they cannot be changed.

Every time Reverse_String is called, the bounds of Res are evaluated
(dynamically), and Res then has these bounds, for the rest of its
lifetime -- which is the duration of the execution of the function -- and
once they are set, they cannot be changed during this lifetime.

So the bounds of the object Res cannot be changed dynamically (they can
be initially /set/ dynamically, but never /changed/ dynamically). Since
the return value is simply Res, this means that the bounds of the return
value are calculated dynamically (but then cannot be changed).

This is different to the strings of many other languages (e.g. BASIC),
in which you can dynamically change the upper bound of a variable at any
time (causing characters to be appended or truncated).

However, Ada supplies the library types
Ada.Strings.Bounded.Generic_Bounded_Strings.Bounded_String and
Ada.Strings.Unbounded.Unbounded_String. These strings types do allow
the upper bound of variables to be changed dynamically. It's just a
pity they have such long names!

> If ada allow dynamic array can be a return value,it mean bounds array
> can be return value?

Yes, the bounds -- both upper and lower -- of Str are passed into the
function  every time it is called, and both bounds of the return result
are also passed out. (It so happens, in this function, that these bounds
are the same.)

The fact that the bounds of Str are passed in is how Str'First, Str'Last,
and Str'Range can be used in the function.

I hope I've made things clear. Please ask if you have any more questions!

-- 
Nick Roberts



^ permalink raw reply	[relevance 4%]

* Re: Constraint Error
    2004-09-30  0:42  6% ` Stephen Leake
@ 2004-09-30  1:11  5% ` tmoran
  1 sibling, 0 replies; 200+ results
From: tmoran @ 2004-09-30  1:11 UTC (permalink / raw)


> m2:=Messages.Create("This is a second test");
will raise Constraint_Error because you attempt to store its 21 characters
into M.Text, which is a 20 character string.  Ada is preventing a buffer
overflow error.

> m1:=Messages.Create("This is a test");
raises Constraint_Error because you attempt to store a 14 character
string into a 20 character M.Text  If you had said, for instance,
  M.Text(1 .. Str'length) := Str;
then it would have stored into the first 14 characters, leaving junk
in the next 6 and no way for a later user of M.Text to know which,
if any, of its characters are non-junk.
Or
  M.Text := Str & (Str'length+1 .. M.Text'length => ' ');
would fill in any unused characters with ' ', which might be what
you would like.

To assign an array (or String, which is just an array of characters)
to another array, their sizes must match.  If they don't match, you
will need to truncate, pad, or just partially fill, as needed.  In
that case you probably want to use a counter or special terminating
character, to remember the "actual" size of the string in M.Text

In the particular case of varying length strings, of course, it would
be easiest to just use Ada.Strings.Bounded or Ada.Strings.Unbounded



^ permalink raw reply	[relevance 5%]

* Re: Constraint Error
  @ 2004-09-30  0:42  6% ` Stephen Leake
  2004-09-30  1:11  5% ` tmoran
  1 sibling, 0 replies; 200+ results
From: Stephen Leake @ 2004-09-30  0:42 UTC (permalink / raw)
  To: comp.lang.ada

"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> writes:

> Hi,
> 
> how can I avoid the Constraint Error, when executing the following code:
> 
> with Messages;
> 
> procedure Test_Messages is
>  M1: Messages.Message;
>  M2: Messages.Message;
> 
> begin
>  m1:=Messages.Create("This is a test");
>  m2:=Messages.Create("This is a second test");
> end Test_Messages;
> ----------------------------
>  package Messages is
>  type Message is tagged private;
>  subtype String_Txt is String(1..20);

This says that all strings will have exactly 20 characters. Not very
flexible.

See Ada.Strings.Bounded and Ada.Strings.Unbounded, in your favorite
Ada manual or textbook.

-- 
-- Stephe




^ permalink raw reply	[relevance 6%]

* Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics
  @ 2004-06-19 20:40  7%                                             ` Robert I. Eachus
  0 siblings, 0 replies; 200+ results
From: Robert I. Eachus @ 2004-06-19 20:40 UTC (permalink / raw)


Martin Dowie wrote:

> No because String is an unconstrained type. You could have
> 
> type Colour_Set is array (Positive) range <>) of String (1 .. 5);
> 
> Red : constant Sgtring := "  Red";
> Green : constant String := "Green";
> Blue : constant String := "Blue";
> 
> Colours : constant Colour_Set (Red, Green, Blue);
> 
> But that's not quite the same thing... (i.e. not a ragged array).

Ah, but you could use Ada.Strings.Bounded:

with Ada.Strings.Bounded;
...
package Color_Strings is new Ada.Strings.Bounded(12);
-- or your choice of bound...

subtype Color_Name is Color_Strings.Bounded_String;

function "+"(Source: in String) return Color_Name is
begin return Color_Strings.To_Bounded_String(Source); end "+";
...
Red: constant Color_Name := +"Red";
Green: constant Color_Name := +"Green";
Blue: constant Color_Name := +"Blue";
Aquamarine: constant Color_Name := +"Aquamarine";
...
type Color_Set is array (Positive range <>) of Color_Name;

Colors: constant Color_Set := (Red, Blue, Green, Aquamarine);

-- Add "u" as appropriate, if you live in Blighty. ;-)

You could also use Unbounded_Strings, but this is the perfect 
application for Bounded_String.  A lot of short strings, of size known 
at compile time.  The other case where I use Bounded_String a lot is in 
binding to databases.  If a text field has a specific length, using 
Bounded_String makes it easy to detect strings too long before starting 
a database transaction.

-- 

                                           Robert I. Eachus

"Reason and experience both forbid us to expect that national morality 
can prevail in exclusion of religious principles." -- George Washington




^ permalink raw reply	[relevance 7%]

* Re: Heterogenous array
  @ 2004-03-01 16:48  6% ` Robert I. Eachus
  0 siblings, 0 replies; 200+ results
From: Robert I. Eachus @ 2004-03-01 16:48 UTC (permalink / raw)


Bj�rn Persson wrote:

> I need an array type that can hold elements of different types. My 
> current attempt (somewhat simplified) is below. My question is, is there 
> a way to do this without pointers?

Sure, try:

with Ada.Strings.Bounded; with Ada.Strings.Unbounded;
package Multirecord is

     package A_Bounded_String is new 
Ada.Strings.Bounded.Generic_Bounded_Length(80);
     subtype A_Bounded_String_Type is A_Bounded_String.Bounded_String;

     type T_Param_Type is (Int, Str);
     type Parameter_Definition(Param_Type : T_Param_Type := Int) is record
        Name : A_Bounded_String_Type;
        case Param_Type is
           when Int =>
              Min : Integer;
              Max : Integer;
              Int_Value : Integer;
           when Str =>
              Str_Value : Ada.Strings.Unbounded.Unbounded_String;
        end case;
     end record;

     type Parameter_Wrapper is record
       Content: Parameter_Definition;
     end record;

     type Parameter_Array is array(Positive range <>) of
                            Parameter_Wrapper;

end Multirecord;

It should compile without problems and do exactly what you want.  The 
type Parameter_Wrapper is needed so that the element type of 
Parameter_Array is constrained.  The rule that requires this may seem 
silly but it is not.  Objects of type Parameter_Definition can be 
different sizes, objects of type Parameter_Wrapper are not.  In effect, 
the reason for having the Parameter_Wrapper type is for the compiler to 
have a hook to do the mutable type thing. (Which in Ada is only a 
property of records with (defaulted) discriminants but never of array 
elements.)

Whether the implementation accomplishes this by making Parameter_Wrapper 
the size of the largest possible Parameter_Definition or uses "hidden" 
pointers is, of course, up to the implementation.  Some compilers alway 
"allocate the max," others only do that if the maximum size is below 
some threshold.  I am not sure whether there are any compilers that 
always use hidden pointers.

-- 
                                           Robert I. Eachus

"The only thing necessary for the triumph of evil is for good men to do 
nothing." --Edmund Burke




^ permalink raw reply	[relevance 6%]

* Re: The "()" operator revisited.
  2004-01-12 22:26  0% ` Robert A Duff
@ 2004-01-13 16:29  0%   ` Frank J. Lhota
  0 siblings, 0 replies; 200+ results
From: Frank J. Lhota @ 2004-01-13 16:29 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
news:wcck73w9536.fsf@shell01.TheWorld.com...
> "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:
>
> > Last June, I proposed that in order to provide an abstract array
capability,
> > Ada 0y should support  user-defined "()" and "():="operators. Since this
> > issue has come up again, I would like to summarize and expand on this
> > proposal.
>
> This is a good idea.  As you note below, it's got a long way to go
> before you've got a list of wording changes to the RM.  For example, the
> notion of operator-named *procedures* does not currently exist in Ada.

First, I'm glad you like the idea. Granted, Ada does not have operator-named
procedures, but there has been discussions about making ":=" an operator.

> But before bothering with that, I think there are some important
> issues to work out:
>
> You seem to be saying that components of arrays (or just abstract
> arrays?) are always passed by copy.  That seems like a real problem,
> since for efficiency, most compilers pass large things by reference.
> (I'm talking about the case of array-of-large-array or
> array-of-large-record.)

I did not mean to imply anything about the parameter passing convention
used. Clearly, we need to support all parameter passing conventions, since
any type can be used as an array component.

The confusion probably arose from the discussion of passing an array
component as a parameter of mode "in out". Now if the array component is
aliased, passing the component by reference is easy: simply pass the address
of the component. If the component is not aliased, as is often the case,
this method would not work. The way many compilers (including GNAT) handle
passing a packed component to a subprogram is:

- Create a temporary variable of the given component type;
- If the parameter is of mode "in" or "in out", unpack the array component
into the temporary variable;
- Pass this temporary variable to the subprogram; and
- If the parameter is of mode "out" or "in out", pack the temporary variable
value into the  array component.

Note that although this requires a temporary copy, it does NOT require that
the subprogram parameter use pass by copy.

Given that this is done currently for packed arrays, there is no good reason
why this cannot be done for the proposed abstract

> Furthermore, if the component type is limited, it is *required* to be
> passed by reference.  This raises the question: can "():=" be declared
> for limited types?

The idea of assigning a limited component to an array component is tricky,
given that there is never to be more than one copy of an object of a limited
type. We can, however, take advantage of the fact that limited objects are
always aliased, and implement such an array as a collection of access values
to the limited objects. For this to work, however, the Value parameter of
"():=" would need to be "in out" mode in order to get a non-constant
reference, so I propose that we also allow "():=" to be declared as

    procedure "():=" ( Source  : in out Abstract_Array_Type;
                       Index_1 : in     Index_Type_1;
                       Index_2 : in     Index_Type_2;
                       ...
                       Index_N : in     Index_Type_N;
                       Value   : in out Component_Type );

I have prototyped this with a limited type.

> What does A(I)'Access mean in this scheme?

Abstract array components, in general, are not aliased, so that expression
would not be legal. In some abstract arrays, however, the components would
be aliased, so we should probably allow the user to specify the access value
to be returned in such cases.

> Are there interactions with Adjust, which is normally called for
> assignment of nonlimited controlled types?

The "()" and "():=" are regular subprograms, so Adjust would be called
whenever the subprogram code requires it.

> You seem to treat 'out' parameters as copy-out only.  But for composite
> types, 'out' means pretty much the same thing as 'in out' -- at least
> *some* parts of the object are copied *in* (see RM for details).
> Likewise, if the component type is an access type, you can't allow
> undefined values to be created -- all access objects have to be
> initialized to 'null' if they aren't initialized to something else
> meaningful.

This type of initialization could easily be done before calling the
subprogram, so I don't see how this is a barrier for abstract arrays.

> You seemed to be hoping that this new notation could underly the
> definition of the *existing* array indexing semantics.  That would be
> elegant.  However, some of the above issues mean it doesn't work -- at
> least as you've defined it so far.

Is there an issue other than parameter passing?

> > Note: the following discussion probably has an insufficient amount of
> > legalese to satisfy language lawyers. Once we've thrashed out these
ideas,
> > I'll be happy to work with anyone with formalizing this proposal.
>
> I hate to be discouraging, but my guess is that a proposal like this is
> *not* going to be accepted by the ARG, even if were written up as proper
> RM wording changes.

That is quite possibly true. I have never done a submission to the ARG
before, so I'm not really up on the procedure. The first step, however, is
to have a solid idea for submission, which is why we're discussing it here.

> > Similar declarations can be added to Ada.Strings.Bounded. This would
permit
> > the higher-level Ada string types to use the same notation as the
low-level
> > standard String type.
>
> Well, it allows that for the particular notation of array indexing,
> and that would be a good thing.  But it doesn't completely solve
> the problem.  It doesn't support slice notation (but I don't think
> slices are all that important).  And it doesn't support string literal
> notation -- I think that *is* important -- it's really annoying that you
> can't have a string literal of type uunbounded string.  Similarly, it
> doesn't support aggregate notation.
>
> If I were designing a language from scratch, I would allow user-defined
> meanings for all of the above notations.  But as I said, unfortunately,
> I don't see this happening for Ada 0X.
>
> - Bob





^ permalink raw reply	[relevance 0%]

* Re: The "()" operator revisited.
  2004-01-12 17:53  3% The "()" operator revisited Frank J. Lhota
@ 2004-01-12 22:26  0% ` Robert A Duff
  2004-01-13 16:29  0%   ` Frank J. Lhota
  0 siblings, 1 reply; 200+ results
From: Robert A Duff @ 2004-01-12 22:26 UTC (permalink / raw)


"Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net> writes:

> Last June, I proposed that in order to provide an abstract array capability,
> Ada 0y should support  user-defined "()" and "():="operators. Since this
> issue has come up again, I would like to summarize and expand on this
> proposal.

This is a good idea.  As you note below, it's got a long way to go
before you've got a list of wording changes to the RM.  For example, the
notion of operator-named *procedures* does not currently exist in Ada.
But before bothering with that, I think there are some important
issues to work out:

You seem to be saying that components of arrays (or just abstract
arrays?) are always passed by copy.  That seems like a real problem,
since for efficiency, most compilers pass large things by reference.
(I'm talking about the case of array-of-large-array or
array-of-large-record.)

Furthermore, if the component type is limited, it is *required* to be
passed by reference.  This raises the question: can "():=" be declared
for limited types?

What does A(I)'Access mean in this scheme?

Are there interactions with Adjust, which is normally called for
assignment of nonlimited controlled types?

You seem to treat 'out' parameters as copy-out only.  But for composite
types, 'out' means pretty much the same thing as 'in out' -- at least
*some* parts of the object are copied *in* (see RM for details).
Likewise, if the component type is an access type, you can't allow
undefined values to be created -- all access objects have to be
initialized to 'null' if they aren't initialized to something else
meaningful.

You seemed to be hoping that this new notation could underly the
definition of the *existing* array indexing semantics.  That would be
elegant.  However, some of the above issues mean it doesn't work -- at
least as you've defined it so far.

> Note: the following discussion probably has an insufficient amount of
> legalese to satisfy language lawyers. Once we've thrashed out these ideas,
> I'll be happy to work with anyone with formalizing this proposal.

I hate to be discouraging, but my guess is that a proposal like this is
*not* going to be accepted by the ARG, even if were written up as proper
RM wording changes.

> Similar declarations can be added to Ada.Strings.Bounded. This would permit
> the higher-level Ada string types to use the same notation as the low-level
> standard String type.

Well, it allows that for the particular notation of array indexing,
and that would be a good thing.  But it doesn't completely solve
the problem.  It doesn't support slice notation (but I don't think
slices are all that important).  And it doesn't support string literal
notation -- I think that *is* important -- it's really annoying that you
can't have a string literal of type uunbounded string.  Similarly, it
doesn't support aggregate notation.

If I were designing a language from scratch, I would allow user-defined
meanings for all of the above notations.  But as I said, unfortunately,
I don't see this happening for Ada 0X.

- Bob



^ permalink raw reply	[relevance 0%]

* The "()" operator revisited.
@ 2004-01-12 17:53  3% Frank J. Lhota
  2004-01-12 22:26  0% ` Robert A Duff
  0 siblings, 1 reply; 200+ results
From: Frank J. Lhota @ 2004-01-12 17:53 UTC (permalink / raw)


Last June, I proposed that in order to provide an abstract array capability,
Ada 0y should support  user-defined "()" and "():="operators. Since this
issue has come up again, I would like to summarize and expand on this
proposal.

Note: the following discussion probably has an insufficient amount of
legalese to satisfy language lawyers. Once we've thrashed out these ideas,
I'll be happy to work with anyone with formalizing this proposal.

The idea is that container libraries, such as the Booch components, Charles
and PragMark, often include collection objects that can be viewed as
generalized arrays. Undoubtedly, the next standard will have some variation
of these container libraries. In support of these generalized arrays, Ada
should allow the array notation to be used for these object. To this end, I
propose adding two operators Ada. The "()" operator, used for reading a
component of an abstract array, has the form:

    function "()" ( Source  : in Abstract_Array_Type;
                    Index_1 : in Index_Type_1;
                    Index_2 : in Index_Type_2;
                    ...
                    Index_N : in Index_Type_N )
       return Component_Type;

Used to write a component of an abstract array, the "():=" operator has the
form

    procedure "():=" ( Source  : in out Abstract_Array_Type;
                       Index_1 : in Index_Type_1;
                       Index_2 : in Index_Type_2;
                       ...
                       Index_N : in Index_Type_N;
                       Value   : in Component_Type );

For a standard array type of the form

    type An_Array is array ( Index_Type_1 range <>, Index_Type_2 range <>,
... ) of Component_Type;

the "()" and "():=" operators are predefined. The predefined versions of
these operators are implicit. For packed arrays, the predefined versions of
"()" and "():="does the usual mask and shift operations to unpack or pack
the given component.

When the "()" function is defined and visible for the type Abstract_Array_Ty
pe, and A is a (possibly constant) object of type Abstract_Array_Type, then
the expression

    A( Index_1, Index_2, ... Index_N )

evaluates to

    "()"( A, Index_1, Index_2, ... Index_N )

Note that the "()" also provides support for an abstract function call
facility.

The "()" operator suffices for presenting a read-only view of a component of
an abstract array type. The "():=" is used in conjunction with "()" to
provide a variable view of an abstract array component. When "():=" operator
is defined and visible for Abstract_Array_Type, and A is a non-constant
object of type Abstract_Array_Type, then the expression

    A( Index_1, Index_2, ... Index_N )

can be assigned a Value of type Component_Type. This assignment is done by
performing the call

    "():="( A, Index_1, Index_2, ... Index_N, Value );

This "():=" call would also be used if A( Index_1, Index_2, ... Index_N ) is
used as an actual parameter for a parameter of mode "out"

When both "()" and "():=" operators are visible for Abstract_Array_Type,
then the expression

    A( Index_1, Index_2, ... Index_N )

can be used as an "in out" parameter. If we have the subprogram

    procedure Fiddle( Item : in out Component_Type );

Then the call

    Fiddle( A( I_1, I_2, ... I_N ) );

is basically equivalent to

    declare
       Temp_Comp : Component_Type := A( I_1, I_2, ... I_N );
    begin
       Fiddle( Temp_Comp );
       A( I_1, I_2, ... I_N ) := Temp_Comp;
    end;

except that the indices are evaluated only once. Note: something like this
is done in Ada95, when dealing with packed arrays.

We can easily define these operators for abstract arrays in Ada95. In the
string package Ada.Strings.Unbounded, we could add

    function "()" (Source : in Unbounded_String;
                   Index  : in Positive)
                   return Character
       renames Element;

    procedure "():=" (Source : in out Unbounded_String;
                      Index  : in     Positive;
                      By     : in     Character)
       renames Replace_Element;

Similar declarations can be added to Ada.Strings.Bounded. This would permit
the higher-level Ada string types to use the same notation as the low-level
standard String type.

Also, one can easily view a Direct I/O file as an abstract array. The
package Ada.Direct_Io can inline the following versions of "()" and "():="
for File_Type:

    function "()" (File  : in File_Type;
                   Index : in Positive_Count)
                   return     Element_Type
    is
       Result : Element_Type;
    begin
       Read( File, Result, From => Index );
       return Result
    end "()";

    procedure "():=" (File  : in File_Type;
                      Index : in Positive_Count;
                      Item  : in Element_Type)
    is
    begin
       Write( File, Item, To => Index );
    end "():=";

A controversial idea: when "()" and "():=" is visible for
Abstract_Array_Type, and A is a non-constant object of type
Abstract_Array_Type, should we allow a declaration like this:

    An_Object : Component_Type renames A( I_1, I_2, I_3, ... I_N );

The idea is that this is a "virtual" object of type Component_Type, where
calls to "()" and "():=" are used to read and write the values of this
object. I'm not entirely sure that this type of "renames" declaration is a
good idea, but I'm interested in what others in this NG think of this.





^ permalink raw reply	[relevance 3%]

* Re: Other Ada Standards (was Re: SIGada Conference)
  2003-12-20  9:06  4%                 ` Nick Roberts
@ 2003-12-20 17:43  6%                   ` Robert I. Eachus
  0 siblings, 0 replies; 200+ results
From: Robert I. Eachus @ 2003-12-20 17:43 UTC (permalink / raw)


Nick Roberts wrote:

> Context clauses must be one of the most frequently used constructs in Ada.
> I think they deserve attention for that reason.

First, I'd like to point out that Bob Duff and I are relatively close in 
our positions on this.  The only issue with adding "with and use" in 
Ada0Y is whether it is worth the cost--and that is a close call.

With implies use can be made to work.  But I think the gymnastics 
required make it a non-starter.  Bob is willing to consider it. ;-)

But I think the relative cost of any with implies use variation is too 
high to make it into this revision.  Adding "with and use" to current 
context clauses should just be a bit of syntactic sugar for most compilers.

Anyone who argues that "with and use" is eight characters longer than 
"use" needs a better text editor.

> I suggest that 'with and use A.B.C;' is used, and means /exactly/ the same
> as 'with A.B.C; use A.B.C;' (it fails if 'with A.B.C;' fails). It's too
> confusing for 'use A.B.C;' to imply 'with A.B;'. I fear a reviewer could be
> sent into a spin searching for a library unit named 'A.B.C'.

I agree.  From the point of view of a reader, "with and use" is a slam 
dunk compared to use implies with.

> I also like the idea of 'with X renames A.B.C;' a lot. I would love to be
> able to write, for example:
> 
>    with ASB renames Ada.Strings.Bounded;
>    procedure ... is
>       ...
>       package My_Strings is new ASB.Generic_Bounded_Length(100);

Interesting idea.  I like it, but I would have to see what it looks like 
fleshed out.  Is the name Ada.Strings.Bounded also visible?  Can I say:

with and use ASB renames Ada.Strings.Bounded; --?

Incidently, you can currently write:

with Ada.Strings.Bounded
package ASB renames Ada.String.Bounded;

in your environment and be done with it.

-- 
                                           Robert I. Eachus

"The war on terror is a different kind of war, waged capture by capture, 
cell by cell, and victory by victory. Our security is assured by our 
perseverance and by our sure belief in the success of liberty." -- 
George W. Bush




^ permalink raw reply	[relevance 6%]

* Re: Other Ada Standards (was Re: SIGada Conference)
  @ 2003-12-20  9:06  4%                 ` Nick Roberts
  2003-12-20 17:43  6%                   ` Robert I. Eachus
  0 siblings, 1 reply; 200+ results
From: Nick Roberts @ 2003-12-20  9:06 UTC (permalink / raw)


Russ wrote:

> ... As I said in an earlier thread, I consider myself like a real estate
>  agent who tells a seller to clear the junk out of the front yard. No, 
> that's not as important as fixing the plumbing and electrical, but it is
>  by far the most cost-effective job the seller can do. If you want to 
> sell Ada, I think you would help your cause to take this "superficial" 
> and "cosmetic" issue seriously.

Hehe. I often feel that when introducing Ada to someone by presenting them
with a minimal Ada program, e.g.:

    procedure Hello is
       Put_Line("Hello World!");
    end;

it somewhat spoils the effect by adding "Oh, and then we have to put 'with
Ada.Text_IO;' in front of that. And then we have to put 'use Ada.Text_IO;'
as well. But Ada is /really/ simple. Honest."

Context clauses must be one of the most frequently used constructs in Ada.
I think they deserve attention for that reason.

I suggest that 'with and use A.B.C;' is used, and means /exactly/ the same
as 'with A.B.C; use A.B.C;' (it fails if 'with A.B.C;' fails). It's too
confusing for 'use A.B.C;' to imply 'with A.B;'. I fear a reviewer could be
sent into a spin searching for a library unit named 'A.B.C'.

I also like the idea of 'with X renames A.B.C;' a lot. I would love to be
able to write, for example:

    with ASB renames Ada.Strings.Bounded;
    procedure ... is
       ...
       package My_Strings is new ASB.Generic_Bounded_Length(100);

-- 
Nick Roberts
  __________________________________________________________
|  Fight Spam! Join EuroCAUCE: http://www.euro.cauce.org/  |
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




^ permalink raw reply	[relevance 4%]

* Re: Declaring subtypes
  @ 2003-12-09 18:47  4% ` tmoran
  0 siblings, 0 replies; 200+ results
From: tmoran @ 2003-12-09 18:47 UTC (permalink / raw)


> ... wondering if declaring subtypes of String for common database
> fields was overkill.
> ...
> subtype Address_Line is String(1..60);
> subtype City is String(1..40);
> ...
> I understand that Strong typing is one of the strengths of Ada but I
> just don't know how far to go with it.
    Strong typing has to do with the compiler warning you when you try
to mix type Apples with type Oranges.  Subtypes merely specify a
constraint.  So Address_Line and City are both of type String and
   Home : Address_Line;
   Home_City   : City;
   ...
   Ada.Text_IO.Put_Line(Home & ", " & Home_City);
   Home(1 .. 40) := Home_City;
does not violate strong typing and is OK (as far as the compiler can
tell).  If you have a database where City is always 40 characters (blank
padded, perhaps), then
  subtype City is String(1..40);
is eminently reasonable.  Ditto for Address_Line etc.  If City is of
varying lengths though, you might want to use the facilities of
Ada.Strings.Bounded or Ada.Strings.Unbounded instead.
  If you want to use strong typing so the compiler will warn you about
mixed types then you need
    type Address_Line is new String(1..60);
    type City is new String(1..40);
If you do that, then
   Home(1 .. 40) := Home_City;
will generate an error message from the compiler.  That may be useful
in catching coding errors.  OTOH,
   Ada.Text_IO.Put_Line(Home & ", " & Home_City);
will also generate an error message, which is probably not so helpful.
To accomplish the same thing you would have to write something like
   Ada.Text_IO.Put_Line(String(Home) & ", " & String(Home_City));
Whether the error checking benefits outweigh the verbosity of the
extra type conversions depends of course on the characteristics of
your particular application.  In this particular example, for instance,
changing the variable "Home" to "Home_Street" would probably lessen
errors like
   Home_Street(1 .. 40) := Home_City;
so it probably wouldn't be worthwhile to go for full separate string types.



^ permalink raw reply	[relevance 4%]

* Re: oo problem help please
  @ 2003-12-09 16:42  5% ` Martin Krischik
  0 siblings, 0 replies; 200+ results
From: Martin Krischik @ 2003-12-09 16:42 UTC (permalink / raw)


shoko wrote:

> what is wrong with the following code:

Wrong choices

> ----car.ads----
> package car is
>   --car class --
>   type car is tagged private;
>   type car_ptr is access all car'class;
>   
>   --car methods --
>   procedure set_name(name:String;this:in out car);
>   function  get_name(this:car) return string;
>   
>  private
>      type car is tagged
>      record
>          name:String(1..256);
>      end record;
>   

I don't belive that every name should be 256 characters long.

> begin
>ᅵᅵᅵᅵᅵcars(1)ᅵ:=ᅵcar_ptr(initbus("mercedes"));
ᅵᅵ
Yes "mercedes" is not 256 Characters. You should take a look at

http://www.adaic.org/standards/95lrm/html/RM-A-4-4.html
http://www.adaic.org/standards/95lrm/html/RM-A-4-5.html

Fact is that you got the wrong type of string. If there is a max lenght
(like you want to store your vechicles in a database) then use
Ada.Strings.Bounded if not use Ada.Strings.Unbounded.

Or if the name is constant use a discriminant:

type car (
    Name_Lenght : Positive)
is tagged record
    name : String(1 .. Name_Lenght);
end record;

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://adacl.sourceforge.net




^ permalink raw reply	[relevance 5%]

* Re: Clause "with and use"
  @ 2003-11-18 17:01  3%                       ` Robert I. Eachus
  0 siblings, 0 replies; 200+ results
From: Robert I. Eachus @ 2003-11-18 17:01 UTC (permalink / raw)


Russ wrote:

> Not being an Ada programmer, I did not even know off the top of my
> head that "with Foo.Bar" is illegal. I'm at work, and my Ada books are
> at home, so let me ask a "newbie" question. Am I correct in assuming
> that "use Foo.Bar" *must* be preceded by "with Foo"? More
> specifically, am I correct in assuming that "use Foo.<anything>"
> *must* be preceded by "with Foo"?
> 
> If so, then the solution seems trivial to me. Let any occurence of
> "use Foo.<anything>" in the context section imply "with Foo". That is,
> for any "use" in the context section, simply take its argument and
> strip off the first "." and anything that follows it, then use that as
> the argument to the implied "with".

Unfortunately, it is not that simple.  You can with library units, and 
child packages are library units, while nested packages are not, so 
whether or not with Foo.Bar is legal in theory requires semantic 
analysis, and in practice requires searching the compilation 
environment.  So when you say "with Ada.Text_IO; use Ada.Text_IO;" yes 
there is an (implied) with of Ada, but there is also a with of 
Ada.Text_IO; then the use clause currently ONLY applies to Ada.Text_IO, 
not to Ada.  That is one of the differences I have been talking about.

> If not, I guess I just made a fool of myself. Oh well.

Just the opposite.  Now you are beginning to participate in the real 
discussion of this issue.  Personally, I don't even use a keyboard 
shortcut for the "with Ada.Text_IO; use Ada.Text_IO;" case.  I type fast 
enough, and that is one of the cases where I often do have a use clause 
in the context clause.  In fact, sometimes I get exactly that far then 
spend sometime thinking.  Do I want to create a generic template now, or 
deal with this I/O package separately?  Do I want this package to be the 
child of something, or standalone, etc.

But if there is a problem here, what we need to understand is both what 
are we trying to fix--if anything--and what are the problems that a fix 
must avoid creating.  For me, there are many packages that are 
descendents of Ada for which I almost automatically put a use clause in 
the context clause.  (There are others, such as Ada.Strings.Bounded 
where the use clause has to be for the instance I create.  Since I tend 
to instantiate them inside other library units, the use clause often 
can't go in the context clause.)  But for library units not in Ada, I 
tend to avoid use clauses in context clauses.  Add to that my typing 
speed, and as I said I don't have a problem with the current rules. 
Doesn't mean that others don't, and I certainly won't be opposed to an 
extension that has no significant drawbacks.  I might feel that there 
are other problems that are more pressing--for example the issue of 
mutually dependent abstractions--but that is an issue of prioritization.

-- 
                                           Robert I. Eachus

100% Ada, no bugs--the only way to create software.




^ permalink raw reply	[relevance 3%]

* Re: Is the Writing on the Wall for Ada?
  2003-10-20  7:43  6%                           ` Jacob Sparre Andersen
@ 2003-10-20 12:20  0%                             ` Marin David Condic
  0 siblings, 0 replies; 200+ results
From: Marin David Condic @ 2003-10-20 12:20 UTC (permalink / raw)


It seems that you favor Unbounded_String as do I. Your usage would look 
similar to mine: Unbounded being favored with Fixed used next most 
frequently. (You can't get entirely away from Fixed since everything in 
the language utilizes it.)

Could you get along fine without Bounded had it never existed? Or do you 
think it was pretty critical where it was used?

MDC


Jacob Sparre Andersen wrote:
> 
> 
> with Ada.Strings.Bounded     27 files
> with Ada.Strings.Fixed        222 files
> with Ada.Strings.Unbounded    401 files
> 
> from a total of 3_041 source files.
> 
> Jacob


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jsf.mil/NSFrames.htm

Send Replies To: m c o n d i c @ a c m . o r g

     "All reformers, however strict their social conscience,
      live in houses just as big as they can pay for."

          --Logan Pearsall Smith
======================================================================




^ permalink raw reply	[relevance 0%]

* Re: Is the Writing on the Wall for Ada?
  @ 2003-10-20  7:43  6%                           ` Jacob Sparre Andersen
  2003-10-20 12:20  0%                             ` Marin David Condic
  0 siblings, 1 reply; 200+ results
From: Jacob Sparre Andersen @ 2003-10-20  7:43 UTC (permalink / raw)


Marin David Condic wrote:

> I'd like to see some semi-reasonable survey of folks doing a "Search 
> *.ad* 'Bounded_String'" on their libraries of Ada95 code and discover if 
> *in practice* it really gets used much. My personal experience is 'not 
> much - if at all.'

with Ada.Strings.Bounded	 27 files
with Ada.Strings.Fixed		222 files
with Ada.Strings.Unbounded	401 files

from a total of 3_041 source files.

Jacob
-- 
from DoD Directive 2000.12

"DEFINITIONS
  (...)
  18. Terrorism.  The calculated use of violence or threat of
  violence to inculcate fear; intended to coerce or to
  intimidate governments or societies in the pursuit of goals
  that are generally political, religious, or ideological."




^ permalink raw reply	[relevance 6%]

* Re: A nongeneric bounded string array type
  2003-10-16  9:33  0%     ` Jean-Pierre Rosen
@ 2003-10-16 18:04  0%       ` Jeffrey Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey Carter @ 2003-10-16 18:04 UTC (permalink / raw)


Jean-Pierre Rosen wrote:

> "Matthew Heaney" <matthewjheaney@earthlink.net> a �crit dans le 
> message de news:uwub7dvnz.fsf@earthlink.net...
> 
>> Stephen Leake <Stephe.Leake@nasa.gov> writes:
>> 
>>> It is also possible to write a direct replacement for 
>>> Ada.Strings.Bounded that is not generic, but takes a discriminant
>>>  for the max length.
>> 
>> There is a bounded string like that in the Charles library:
>> 
>> charles.strings.bounded
>> 
>> <http://home.earthlink.net/~matthewjheaney/charles/>
>> 
> Or use the Variable_String package, available from Adalog's 
> components page: http://www.adalog.fr/compo2.htm

The Ada-83 PragmAda Reusable Components also had such a type, but with
the inclusion of bounded and unbounded strings in Ada in 1995, it was
dropped. It's generally better to have, and use, a standard form, even
if it's not exactly how you'd do it yourself, than to write something 
that does the same thing.

-- 
Jeff Carter
"Perfidious English mouse-dropping hoarders."
Monty Python & the Holy Grail
10




^ permalink raw reply	[relevance 0%]

* Re: A nongeneric bounded string array type
  2003-10-15  3:28  0%   ` Matthew Heaney
@ 2003-10-16  9:33  0%     ` Jean-Pierre Rosen
  2003-10-16 18:04  0%       ` Jeffrey Carter
  0 siblings, 1 reply; 200+ results
From: Jean-Pierre Rosen @ 2003-10-16  9:33 UTC (permalink / raw)


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


"Matthew Heaney" <matthewjheaney@earthlink.net> a �crit dans le message de news:uwub7dvnz.fsf@earthlink.net...
> Stephen Leake <Stephe.Leake@nasa.gov> writes:
>
> > It is also possible to write a direct replacement for
> > Ada.Strings.Bounded that is not generic, but takes a discriminant for
> > the max length.
>
> There is a bounded string like that in the Charles library:
>
> charles.strings.bounded
>
> <http://home.earthlink.net/~matthewjheaney/charles/>
>
Or use the Variable_String package, available from Adalog's components page:
http://www.adalog.fr/compo2.htm

-- 
---------------------------------------------------------
           J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr





^ permalink raw reply	[relevance 0%]

* Re: A nongeneric bounded string array type (was Re: Is the Writing on the Wall for Ada?)
  @ 2003-10-15 16:11  0%                                           ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 200+ results
From: Warren W. Gay VE3WWG @ 2003-10-15 16:11 UTC (permalink / raw)


Robert I. Eachus wrote:
> Warren W. Gay VE3WWG wrote:
> 
>> I think your package is addressing some other poster's wishes here
> 
>> I was simply referring to the need to instantiate different
>> bounded strings for _different_ variables. Arrays, of course
>> present another challenge, which is the problem you have proposed
>> a solution to.
> 
> Ah, but I find I most often use Ada.Strings.Bounded for return values 
> from database queries where you can get an arbitrary number of matches 
> returned.  The new package is perfect for that role, since I just have 
> to with the package and not worry about setting maximum string lengths.

Ah, but "arbitrary number of matches" could mean billions of
rows! Do you really want to process columns that way? ;-)
--
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg




^ permalink raw reply	[relevance 0%]

* Re: A nongeneric bounded string array type
    2003-10-10 20:57  4%   ` Robert I. Eachus
@ 2003-10-15  3:28  0%   ` Matthew Heaney
  2003-10-16  9:33  0%     ` Jean-Pierre Rosen
  1 sibling, 1 reply; 200+ results
From: Matthew Heaney @ 2003-10-15  3:28 UTC (permalink / raw)


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

> It is also possible to write a direct replacement for
> Ada.Strings.Bounded that is not generic, but takes a discriminant for
> the max length.

There is a bounded string like that in the Charles library:

charles.strings.bounded

<http://home.earthlink.net/~matthewjheaney/charles/>




^ permalink raw reply	[relevance 0%]

* Re: A nongeneric bounded string array type
  @ 2003-10-10 20:57  4%   ` Robert I. Eachus
  2003-10-15  3:28  0%   ` Matthew Heaney
  1 sibling, 0 replies; 200+ results
From: Robert I. Eachus @ 2003-10-10 20:57 UTC (permalink / raw)


Stephen Leake wrote:
> "Robert I. Eachus" <rieachus@comcast.net> writes:
> 
> 
>>Warren W. Gay VE3WWG wrote:
>>
>>
>>>One of the things that discourages me from using Bounded_Strings is
>>>the number of instantiations that you end up making (for each
>>>different string size). I would have preferred one instantiation,
>>>and then a discriminant that set the maximum size on the object.
>>>But that may have problems of its own.
>>
>>Ask, and it shall be given unto you; seek, and you shall find; knock,
>>and it shall be opened to you. -- Matthew 7:7
>>
>>Sorry, I couldn't resist.  Here is a package with NO instantiations,
>>and a bounded array type that can handle different length strings.

> Well, I don't think I've ever needed a container of strings (which is
> one way to describe this thing). I've needed symbol tables and such,
> which contain strings, but also contain other things.

The usual case where I have been using Ada.String.Bounded is when I am 
doing a database query (often from a web page) and displaying the 
results.  (I should probably use AWS, but I'm lazy, and I have been 
using uncgi directly from Ada for a long time.)  With this type I can 
just have the query return a Bounded_String_Array and display it.

>>You had better believe that if this pattern is this hard to find, it
>>probably belongs in the standard, rather than in my back pocket. 
> 
> Hmm. If someone said to me "please write a container of strings, in
> Ada 83, with no dynamic memory allocation", this is probably what I
> would have come up with.

Um, Ada.Strings.Bounded is what I came up with.  But finally, someone 
asked for a container that can be used for "ragged" string arrays, 
without using generics.

The hard part was realizing that it wasn't impossible.  I had just 
finished writing something that implied it wasn't impossible, so I did 
it.  And once you realize that it is possible, elegant packaging isn't 
hard.

It is just like asking someone to design a transportation system from 
here to the moon--that doesn't use rockets.  With beanstalks and tether 
systems it is possible, but lots of people would look at the conditions, 
say that's crazy, and not even try.  (Incidently carbon nanotube 
technology looks like it will make Earth beanstalks not only possible, 
but practical.  A Martian beanstalk or a lunar beanstalk though the L1 
Lagrange point are both highly practical even with just Kevlar.)

-- 
                                                     Robert I. Eachus

"Quality is the Buddha. Quality is scientific reality. Quality is the 
goal of Art. It remains to work these concepts into a practical, 
down-to-earth context, and for this there is nothing more practical or 
down-to-earth than what I have been talking about all along...the repair 
of an old motorcycle."  -- from Zen and the Art of Motorcycle 
Maintenance by Robert Pirsig




^ permalink raw reply	[relevance 4%]

Results 1-200 of ~500   | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2003-09-06 21:47     Is the Writing on the Wall for Ada? Warren W. Gay VE3WWG
2003-09-25 18:04     ` Jan Kroken
2003-09-25 21:50       ` Stephen Leake
2003-09-25 22:06         ` Hyman Rosen
2003-09-26  1:53           ` Robert I. Eachus
2003-09-26  2:31             ` Matthew Heaney
2003-09-29  2:46               ` Craig Carey
2003-09-30  2:20                 ` Robert I. Eachus
2003-09-30  7:01                   ` Preben Randhol
2003-09-30 12:30                     ` Marin David Condic
2003-09-30 14:28                       ` Jean-Pierre Rosen
2003-10-01 12:17                         ` Marin David Condic
2003-10-01 13:50                           ` Jean-Pierre Rosen
2003-10-02  0:38                             ` Marin David Condic
2003-10-20  7:43  6%                           ` Jacob Sparre Andersen
2003-10-20 12:20  0%                             ` Marin David Condic
2003-10-01 21:54                           ` tmoran
2003-10-02  0:50                             ` Marin David Condic
2003-10-02 20:03                               ` Robert I. Eachus
2003-10-03 12:22                                 ` Marin David Condic
2003-10-04  1:49                                   ` Robert I. Eachus
2003-10-04 12:31                                     ` Marin David Condic
2003-10-06 16:47                                       ` Warren W. Gay VE3WWG
2003-10-08 17:57                                         ` A nongeneric bounded string array type (was Re: Is the Writing on the Wall for Ada?) Robert I. Eachus
2003-10-09 16:47                                           ` Warren W. Gay VE3WWG
2003-10-10 17:40                                             ` Robert I. Eachus
2003-10-15 16:11  0%                                           ` Warren W. Gay VE3WWG
2003-10-10 17:18     A nongeneric bounded string array type Robert I. Eachus
2003-10-10 17:48     ` Stephen Leake
2003-10-10 20:57  4%   ` Robert I. Eachus
2003-10-15  3:28  0%   ` Matthew Heaney
2003-10-16  9:33  0%     ` Jean-Pierre Rosen
2003-10-16 18:04  0%       ` Jeffrey Carter
2003-11-11 22:08     Clause "with and use" Vinzent 'Gadget' Hoefler
2003-11-13  7:26     ` Russ
2003-11-13 19:59       ` Chad R. Meiners
2003-11-14  5:45         ` Russ
2003-11-14  7:51           ` Chad R. Meiners
2003-11-14 23:23             ` Russ
2003-11-15 15:19               ` Robert I. Eachus
2003-11-15 16:15                 ` Gautier Write-only
2003-11-16  0:02                   ` Robert I. Eachus
2003-11-17  9:04                     ` Dmitry A. Kazakov
2003-11-17 14:38                       ` Robert I. Eachus
2003-11-17 19:40                         ` Russ
2003-11-18 17:01  3%                       ` Robert I. Eachus
2003-12-08 19:49     oo problem help please shoko
2003-12-09 16:42  5% ` Martin Krischik
2003-12-09 15:10     Declaring subtypes Kevin Hostelley
2003-12-09 18:47  4% ` tmoran
     [not found]     <468D78E4EE5C6A4093A4C00F29DF513D04B82B08@VS2.hdi.tvcabo>
2003-12-17  1:01     ` SIGada Conference Stephen Leake
2003-12-17  3:19       ` Robert I. Eachus
2003-12-18  6:55         ` Robert C. Leif
2003-12-18 15:23           ` Other Ada Standards (was Re: SIGada Conference) Robert I. Eachus
2003-12-18 18:27             ` Robert A Duff
2003-12-19  8:51               ` Russ
2003-12-19 23:18                 ` Robert A Duff
2003-12-20  7:05                   ` Russ
2003-12-20  9:06  4%                 ` Nick Roberts
2003-12-20 17:43  6%                   ` Robert I. Eachus
2004-01-12 17:53  3% The "()" operator revisited Frank J. Lhota
2004-01-12 22:26  0% ` Robert A Duff
2004-01-13 16:29  0%   ` Frank J. Lhota
2004-03-01  1:53     Heterogenous array Björn Persson
2004-03-01 16:48  6% ` Robert I. Eachus
2004-05-30 11:46     Improving Ada's image - Was: 7E7 Flight Controls Electronics Per Dalgas Jakobsen
2004-06-08 22:23     ` Hyman Rosen
2004-06-09  2:27       ` Warren W. Gay VE3WWG
2004-06-09  6:39         ` Hyman Rosen
2004-06-10 12:13           ` Marin David Condic
2004-06-11 12:48             ` Warren W. Gay VE3WWG
2004-06-11 17:31               ` Marin David Condic
2004-06-14  2:30                 ` Berend de Boer
2004-06-14  3:10                   ` Hyman Rosen
2004-06-14 11:49                     ` Marin David Condic
2004-06-14 16:28                       ` Warren W. Gay VE3WWG
2004-06-15 11:26                         ` Marin David Condic
2004-06-15 16:43                           ` Warren W. Gay VE3WWG
2004-06-15 18:51                             ` Hyman Rosen
2004-06-15 21:02                               ` Warren W. Gay VE3WWG
2004-06-15 22:01                                 ` Hyman Rosen
2004-06-15 22:08                                   ` Ed Falis
2004-06-15 22:26                                     ` Hyman Rosen
2004-06-17 15:50                                       ` Robert I. Eachus
2004-06-17 16:12                                         ` Hyman Rosen
2004-06-17 21:05                                           ` Pascal Obry
2004-06-17 23:02                                             ` Brian May
2004-06-18  7:50                                               ` Martin Dowie
2004-06-19 20:40  7%                                             ` Robert I. Eachus
2004-09-29 23:24     Constraint Error Rick Santa-Cruz
2004-09-30  0:42  6% ` Stephen Leake
2004-09-30  1:11  5% ` tmoran
     [not found]     <cklea4$9eb$1@netnews.hinet.net>
2004-10-14 17:24  4% ` dynamic array as return value? Nick Roberts
2004-12-08 16:46  6% XML Strings in Ada Robert C. Leif
2005-08-03 10:24  2% [Announce] AVR-Ada V0.3 released rolf.ebert_nospam_
2005-10-17  6:59     Dinamic String TC
2005-10-17  7:19     ` Martin Dowie
2005-10-17 19:23  5%   ` Jeffrey R. Carter
2005-11-21 19:40     Initialize with aggregate? ejijott
2005-11-21 22:21     ` Robert A Duff
2005-11-22 16:57  5%   ` Adam Beneschan
2005-11-22 20:07  0%     ` Robert A Duff
2005-11-23 17:36     Filenames in Ada Martin Krischik
2005-11-23 22:18     ` Randy Brukardt
2005-11-24  3:21  6%   ` Silly question about strings (was: Filenames in Ada) Steve
2005-11-24  4:58  0%     ` Larry Kilgallen
2006-03-27 20:05  5% ada and pl/sql Jason King
2006-03-27 20:28  0% ` Georg Bauhaus
2006-03-27 21:07  0% ` Björn Persson
     [not found]     <1151691630.276880.203280@75g2000cwc.googlegroups.com>
2006-06-30 20:12  5% ` Is there an end of string like in C Jeffrey R. Carter
2006-11-14 22:51     STRING length markww
2006-11-14 22:24  6% ` Georg Bauhaus
2006-11-15  0:44  0%   ` markww
2006-11-15  1:09  0%     ` markww
2006-11-29 17:30     Strings and errors... (gnat) tr00per
2006-11-29 17:44     ` Robert A Duff
2006-11-29 17:57       ` tr00per
2006-11-29 18:10  7%     ` Ludovic Brenta
2007-02-21 18:09     Text Processing in Ada 95 Rob Norris
2007-02-22  2:45  5% ` Jeffrey R. Carter
2008-03-02  0:23     Private type definition must be definite : but why ? Hibou57 (Yannick Duchêne)
2008-03-02  0:37     ` Hibou57 (Yannick Duchêne)
2008-03-03 16:29  4%   ` Adam Beneschan
2008-03-31 22:44     Untyped Ada? Phaedrus
2008-04-01 17:09     ` Pascal Obry
2008-04-01 22:00       ` Phaedrus
2008-04-04 15:16         ` Graham
2008-04-04 16:10           ` Pascal Obry
2008-04-04 21:09             ` Ada.Bounded_Strings Adam Beneschan
2008-04-04 21:15 12%           ` Ada.Strings.Bounded Adam Beneschan
2008-04-05  4:39 10%             ` Ada.Strings.Bounded Gautier
2008-04-05  9:43  5%               ` Ada.Strings.Bounded Pascal Obry
2008-04-05 10:10  5%                 ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-05 11:36  5%                 ` Ada.Strings.Bounded Gautier
2008-04-05 12:14  6%                   ` Ada.Strings.Bounded Pascal Obry
2008-04-06  0:31  6%                     ` Ada.Strings.Bounded Randy Brukardt
2008-04-07 14:57  5%                       ` Ada.Strings.Bounded Adam Beneschan
2008-04-07 15:23  6%                         ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-07 16:34  6%                         ` Ada.Strings.Bounded stefan-lucks
2008-04-07 17:34  6%                           ` Ada.Strings.Bounded (see below)
2008-04-12 18:50  3%                 ` Ada.Strings.Bounded Eric Hughes
2008-04-12 19:46  5%                   ` Ada.Strings.Bounded Georg Bauhaus
2008-04-13 16:53  5%                     ` Ada.Strings.Bounded Eric Hughes
2008-04-13 20:10  6%                       ` Ada.Strings.Bounded Robert A Duff
2008-04-13 23:52  4%                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14  8:00  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-14 15:25  6%                             ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:36  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15  1:39  6%                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-12 21:09  5%                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-13 16:31  3%                     ` Ada.Strings.Bounded Eric Hughes
2008-04-13 20:02  4%                       ` Ada.Strings.Bounded Robert A Duff
2008-04-13 23:20  2%                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14  9:07  6%                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-14 15:50  5%                             ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:52  6%                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15  2:07  4%                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-15  8:02  6%                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15 14:20  5%                                     ` Ada.Strings.Bounded Eric Hughes
2008-04-15 15:23  6%                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16  2:51  6%                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-16  8:00  6%                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
     [not found]                                         ` <bc3a8b4e-63fe-47a6-b10b-7056f6d7d586@w5g2000prd.googlegroups.com>
2008-04-15 14:58  6%                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16  2:46  6%                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-16  8:16  6%                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16 14:40  3%                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-16 18:28  5%                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-21  0:44  5%                                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-21 14:08  5%                                                   ` Ada.Strings.Bounded Robert A Duff
2008-04-21 16:35  3%                                                     ` Ada.Strings.Bounded Eric Hughes
2008-04-21 18:04  4%                                                       ` Ada.Strings.Bounded Robert A Duff
2008-04-22  0:19  3%                                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-22  0:49  6%                                                           ` Ada.Strings.Bounded Adam Beneschan
2008-04-22  1:02  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
2008-04-22 15:30  6%                                                               ` Ada.Strings.Bounded Eric Hughes
2008-04-22 16:08  5%                                                                 ` Ada.Strings.Bounded Robert A Duff
2008-04-22 15:25  5%                                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-22 15:54  5%                                                               ` Ada.Strings.Bounded Robert A Duff
2008-04-22 15:41  4%                                                           ` Ada.Strings.Bounded Robert A Duff
2008-04-22 17:49  6%                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 18:26  6%                                                               ` Ada.Strings.Bounded Samuel Tardieu
2008-04-22 18:59  6%                                                                 ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 18:47  5%                                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-22 19:19  6%                                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 19:41  6%                                                               ` Ada.Strings.Bounded Robert A Duff
2008-04-22 22:55  6%                                                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-23  6:40  6%                                                                   ` Ada.Strings.Bounded christoph.grein
2008-04-23  6:54  6%                                                                     ` Ada.Strings.Bounded christoph.grein
2008-04-23 10:42  6%                                                                 ` Ada.Strings.Bounded Georg Bauhaus
2008-04-23 12:32  5%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-23 12:52  6%                                                                   ` Ada.Strings.Bounded christoph.grein
2008-04-23 13:34  6%                                                                     ` Ada.Strings.Bounded Georg Bauhaus
2008-04-23 15:12  6%                                                                   ` Ada.Strings.Bounded Adam Beneschan
2008-04-23 15:36  6%                                                                     ` Ada.Strings.Bounded (see below)
2008-04-23 17:09  6%                                                                     ` Ada.Strings.Bounded Ray Blaak
2008-04-24  0:29  4%                                                                   ` Ada.Strings.Bounded Randy Brukardt
2008-04-22 20:15  4%                                                               ` Ada.Strings.Bounded Adam Beneschan
2008-04-23 13:14  6%                                                                 ` Ada.Strings.Bounded Peter Hermann
2008-04-23 14:40  6%                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-23 15:03  6%                                                                     ` Ada.Strings.Bounded Adam Beneschan
2008-04-22 19:56  5%                                                             ` Ada.Strings.Bounded Adam Beneschan
2008-04-21 18:50  5%                                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22  0:31  6%                                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14 15:11  6%                   ` Ada.Strings.Bounded Adam Beneschan
2008-04-14 16:09  6%                     ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:13  6%                       ` Ada.Strings.Bounded Georg Bauhaus
2008-04-15  1:35  4%                         ` Ada.Strings.Bounded Eric Hughes
2008-04-15 20:33  6%                           ` Ada.Strings.Bounded Georg Bauhaus
2008-04-16  3:11  6%                             ` Ada.Strings.Bounded Eric Hughes
2008-04-04 23:35               ` Ada.Bounded_Strings Robert A Duff
2008-04-05  1:46  4%             ` Ada.Bounded_Strings Adam Beneschan
2008-04-05  4:55  0%               ` Ada.Bounded_Strings Randy Brukardt
2008-04-05  7:30  0%                 ` Ada.Bounded_Strings Dmitry A. Kazakov
2008-06-20  9:03  5% another way to shoot yourself in the foot? fedya_fedyakoff
2008-06-23 14:21     Limited returns Dmitry A. Kazakov
2008-06-23 15:04     ` fedya_fedyakoff
2008-06-23 15:20       ` fedya_fedyakoff
2008-06-23 16:53         ` Dmitry A. Kazakov
2008-06-24 10:56  5%       ` fedya_fedyakoff
2008-09-13 14:18     Array of Strings jedivaughn
2008-09-13 14:32  6% ` Ludovic Brenta
2009-09-24  0:47  5% Table of pointers question Rob Solomon
2010-04-17 13:21     confusion with string initialization brett
2010-04-17 17:42  7% ` 
2010-04-18  2:13  7% ` brett
2010-04-19 14:54       ` Colin Paul Gloster
2010-04-19 14:12         ` J-P. Rosen
2010-04-19 18:20  7%       ` John B. Matthews
2011-01-20 20:21     problems with interfacing c Stoik
2011-01-20 20:56     ` Dmitry A. Kazakov
2011-01-28  0:39       ` Stoik
2011-01-28  9:41  5%     ` Ludovic Brenta
2013-01-30  0:44     Ada and string literals codeallergy
2013-01-30  7:08     ` Niklas Holsti
2013-01-30 11:50       ` Mart van de Wege
2013-01-30 13:52  5%     ` Niklas Holsti
2013-08-09 16:50     4 beginner's questions on the PL Ada Emanuel Berg
2013-08-09 17:09     ` Adam Beneschan
2013-08-09 19:01       ` Randy Brukardt
2013-08-09 21:38         ` Emanuel Berg
2013-08-09 22:00           ` Jeffrey Carter
2013-08-09 22:16             ` Emanuel Berg
2013-08-10  0:39               ` Anh Vo
2013-08-10  1:24                 ` Emanuel Berg
2013-08-10  6:16  6%               ` Simon Wright
2013-08-18 21:05     Hash Type Size sbelmont700
2013-08-19 22:12     ` Randy Brukardt
2013-08-31  6:22       ` Peter Brooks
2013-08-31 15:57         ` sbelmont700
2013-09-03  1:47           ` Randy Brukardt
2013-09-03  2:31             ` Peter Brooks
2013-09-03 10:50  5%           ` John B. Matthews
2013-09-03 17:18  0%             ` Peter Brooks
2013-09-03 21:21  0%               ` John B. Matthews
2013-10-02  2:58     Optimizing Ada kennethesills
2013-10-02  3:47     ` Jeffrey Carter
2013-10-02  3:53       ` kennethesills
2013-10-02  4:13         ` Jeffrey Carter
2013-10-02 18:58  5%       ` John B. Matthews
2013-12-05  3:58  6% Reason for 'Ada.Strings.Bounded' not being declared 'pragma Pure' ? Rod Kay
2013-12-05  6:50  6% ` Shark8
2013-12-05  8:16  6%   ` Rod Kay
2013-12-05  9:51  6% ` Georg Bauhaus
2013-12-05 20:17 10%   ` Randy Brukardt
2013-12-06  3:03 11%     ` Brad Moore
2013-12-06  4:43  6%       ` Rod Kay
2013-12-06  4:36  6%     ` Rod Kay
2013-12-06  4:28  6%   ` Rod Kay
2014-03-25 21:41     Your wish list for Ada 202X Stoik
2014-03-26  6:25     ` Shark8
2014-03-26 20:41       ` Randy Brukardt
2014-03-27  9:20         ` Shark8
2014-03-27 21:50           ` Randy Brukardt
2014-03-28  8:17             ` Dmitry A. Kazakov
2014-03-28 21:27  5%           ` Randy Brukardt
2014-03-29  9:44  0%             ` Dmitry A. Kazakov
2014-03-31 23:55  0%               ` Randy Brukardt
2014-05-19 10:10  6% Strange compile-time error with Ada.Containers.Indefinite_Hashed_Maps mockturtle
2014-08-02 13:10     trimming strings agent
2014-08-02 17:22     ` mockturtle
2014-08-03 21:42       ` agent
2014-08-03 23:14  5%     ` Georg Bauhaus
2014-08-09 15:20     Warning: Storage error Victor Porton
2014-08-09 16:08  5% ` Jeffrey Carter
2014-08-09 16:26  5%   ` Dmitry A. Kazakov
2014-08-09 16:46  6%     ` Jeffrey Carter
2014-10-03 23:29     array of string Stribor40
2014-10-07  1:06  5% ` brbarkstrom
2014-10-07 16:49  7% ` brbarkstrom
2014-11-21 11:41     How to get nice with GNAT? Natasha Kerensikova
2014-11-23 17:41     ` brbarkstrom
2014-11-23 20:49       ` Jeffrey Carter
2014-11-24  3:05  5%     ` brbarkstrom
2015-04-24 21:40     Annoying behavior Laurent
2015-04-25 13:54     ` Stephen Leake
2015-04-25 15:46       ` Laurent
2015-04-26 10:38         ` Jedi Tek'Unum
2015-04-26 11:52           ` Textedit and txt Laurent
2015-04-26 13:21  4%         ` brbarkstrom
2015-05-06 21:23  0%           ` Randy Brukardt
2015-05-07 21:12  6%             ` Laurent
2015-05-09 15:23  0%               ` brbarkstrom
2015-06-21 18:38     Is there an easier way for this? Laurent
2015-06-21 19:25     ` Jeffrey R. Carter
2015-06-22 16:41       ` Laurent
2015-06-22 16:47         ` Jeffrey R. Carter
2015-06-22 17:18           ` Laurent
2015-06-22 18:04             ` What do you think about this? Laurent
2015-06-23 14:21               ` Stephen Leake
2015-06-23 19:51  4%             ` Laurent
2015-06-23 20:20  0%               ` Anh Vo
2015-11-10 22:00  6% Bounded String question Serge Robyns
2015-11-11  0:48  7% ` Bob Duff
2015-11-11 10:52  0%   ` Serge Robyns
2015-11-11 13:43         ` Serge Robyns
2015-11-11 17:27  6%       ` Jeffrey R. Carter
2015-11-11 20:06  7%         ` Serge Robyns
2015-11-11 20:23  7%           ` AdaMagica
2015-11-11 20:32  0%             ` Serge Robyns
2015-11-11 20:40  6%               ` AdaMagica
2015-11-12 18:03  0%                 ` G.B.
2015-11-12 18:13  0%                   ` Serge Robyns
2015-11-12 18:14  0%                     ` Serge Robyns
2015-11-12 19:37  0%                   ` Randy Brukardt
2015-11-11 20:42  0%           ` Jeffrey R. Carter
2015-11-11 15:41  0%     ` Bob Duff
2017-08-03  5:45     Community Input for the Maintenance and Revision of the Ada Programming Language Randy Brukardt
2017-09-11 18:49     ` Tarjei Jensen
2017-09-11 19:33       ` Dmitry A. Kazakov
2017-09-12  6:18         ` Tarjei Jensen
2017-09-12  6:38  5%       ` gautier_niouzes
2017-09-12  7:02  0%         ` Tarjei Jensen
2017-09-12  7:15  0%           ` Dmitry A. Kazakov
2017-09-12  9:23                 ` J-P. Rosen
2017-09-12 10:07                   ` Dmitry A. Kazakov
2017-09-12 16:30                     ` Shark8
2017-09-12 16:58  6%                   ` Dmitry A. Kazakov
2017-09-12  6:39           ` Egil H H
2017-09-12  7:02             ` Tarjei Jensen
2017-09-12  7:42               ` Egil H H
2017-09-12  8:35  6%             ` Dmitry A. Kazakov
2017-09-12  9:21                   ` Egil H H
2017-09-12 10:22                     ` Dmitry A. Kazakov
2017-09-12 10:48                       ` Egil H H
2017-09-12 12:09  6%                     ` Dmitry A. Kazakov
2017-09-12 12:56  0%                       ` Egil H H
2017-09-12 13:14  0%                         ` Dmitry A. Kazakov
2017-09-12 13:25                               ` Egil H H
2017-09-12 13:43                                 ` Dmitry A. Kazakov
2017-09-12 14:07                                   ` Egil H H
2017-09-12 15:59  6%                                 ` Dmitry A. Kazakov
2017-09-12 14:36                                   ` Egil H H
2017-09-12 15:55  5%                                 ` Dmitry A. Kazakov
2017-09-12 16:15  4%                                   ` Egil H H
2017-09-12 16:40  0%                                     ` Dmitry A. Kazakov
2017-09-12 16:47                                           ` Egil H H
2017-09-12 16:59                                             ` Dmitry A. Kazakov
2017-09-12 17:03  5%                                           ` Egil H H
2017-09-12 17:17  7%                                             ` Dmitry A. Kazakov
2017-09-12 17:29  0%                                               ` Egil H H
2017-09-12 19:14  0%                                                 ` Dmitry A. Kazakov
2017-09-21 18:14     Ada.Strings.Unbounded vs Ada.Containers.Indefinite_Holders Victor Porton
2017-09-21 21:30     ` AdaMagica
2017-09-22 12:16       ` Victor Porton
2017-09-22 19:25         ` Simon Wright
2017-09-22 22:15           ` Victor Porton
2017-09-23  8:09             ` Dmitry A. Kazakov
2017-09-23  9:16  5%           ` Jeffrey R. Carter
2018-01-15  1:18     ADA.STRINGS.INDEX_ERROR : a-strunb.adb:782 Mehdi Saada
2018-01-15  3:23  5% ` Niklas Holsti
2018-04-15 21:48     How to get Ada to “cross the chasm”? Dan'l Miller
2018-04-30 11:28  4% ` Mehdi Saada
2018-04-30 12:39  0%   ` Dmitry A. Kazakov
2021-02-08 11:22     [ANN] UXStrings package available (UXS_20210207) Blady
2021-02-11  8:19  6% ` Emmanuel Briot
2021-02-27  9:14  0%   ` Blady
2021-03-06 18:13  0%     ` Blady
2021-04-17 22:03     Ada and Unicode DrPi
2021-04-19  9:08     ` Stephen Leake
2021-04-19 11:56       ` Luke A. Guest
2021-04-19 12:52         ` Dmitry A. Kazakov
2021-04-19 13:00           ` Luke A. Guest
2021-04-19 13:24             ` J-P. Rosen
2022-04-03 18:04               ` Thomas
2022-04-06 18:57                 ` J-P. Rosen
2022-04-07  1:30  5%               ` Randy Brukardt
2021-11-29 17:34     Empty String confusion; Positive and Natural Kevin Chadwick
2021-11-29 19:19     ` Niklas Holsti
2021-11-29 22:50       ` Kevin Chadwick
2021-11-30  8:29  5%     ` Simon Wright
2021-11-30  8:34  5%     ` Niklas Holsti

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