Ok ... ADA online documentation is POOR. Lots of
definitions, often NO practical examples of even
the simplest things. You'd expect more for an
"official DOD" language.
Problem : I want to find out if/where a substring
is in another string (lets assume unbounded strings).
The docs say to use Index(source,substr,<something>,<something-identity>)
Well, I can guess what the first two are. The third probably
is "forward" or maybe '1' for "start at first'. However all
examples of Index have some kind of mapping param for #4
and I've used every search engine and CANNOT figure out what
goes in there.
All that works fine. The very last thing I wanted to
add was a "is substring in string" function - might
return a boolean, but I might cheat and return a real
with the listindex .point. position-in-str sort of format.
The docs say to use Index(source,substr,<something>,<something-identity>)
On 2022-01-05 01:54, 1.AAC0831 wrote:
The docs say to use Index(source,substr,<something>,<something-identity>)
I don't know what "docs" you mean. Anyone using Ada should be familiar
with its standard library, which is documented in Annex A of the ARM at
http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A.html
(I provide the link to the AARM as the annotations are sometimes useful.)
The documentation for Ada.Strings.Fixed is at
http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-4-3.html
and lists 6 functions named Index (and 2 for Index_Non_Blank). Of these
I mostly use the one at paragraph 9:
9 function Index (Source : in String;
Pattern : in String;
Going : in Direction := Forward;
Mapping : in Maps.Character_Mapping
:= Maps.Identity)
return Natural;
with the defaults for the last 2 parameters. Occasionally I've used a
Going => Backward,
The Mapping/Test parameters are for specialized needs, such as case-insensitive matching or folding accented characters together, and
the default will work if you don't need anything like that.
On 5/1/22 11:54 am, 1.AAC0831 wrote:
Ok ... ADA online documentation is POOR. Lots of
definitions, often NO practical examples of even
the simplest things. You'd expect more for an
"official DOD" language.
With a duckduckgo search on "ada string index", the first hit is ...
https://learn.adacore.com/courses/intro-to-ada/chapters/standard_library_strings.html
... which provides a simple example of the 'Index' function.
Problem : I want to find out if/where a substring
is in another string (lets assume unbounded strings).
The docs say to use Index(source,substr,<something>,<something-identity>)
Well, I can guess what the first two are. The third probably
is "forward" or maybe '1' for "start at first'. However all
examples of Index have some kind of mapping param for #4
and I've used every search engine and CANNOT figure out what
goes in there.
https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-2.html
https://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-4-3.html
In many/most cases, the default parameters for 'Mapping' are fine.
All that works fine. The very last thing I wanted to
add was a "is substring in string" function - might
return a boolean, but I might cheat and return a real
with the listindex .point. position-in-str sort of format.
function Contains (Source : in String; Pattern : in String)
return Boolean
is
use Ada.Strings.Fixed;
begin
return Index (Source, Pattern) /= 0;
end Contains;>
In summary, Ada is one of the the best documented languages in existence. Consider the 'Language Reference Manual', the 'Ada
Rationale's and the 'Ada Quality and Style Guide's.
Furthermore the resources at 'https://learn.adacore.com' and 'https://www.adacore.com/gems' provide many examples of best practices
in specific areas of interest.
Finally, forums such as 'comp.lang.ada' and the '#ada' irc channel
on the 'irc.libera.chat' server are great places to quickly find answers.
Regards.
https://learn.adacore.com/courses/intro-to-ada/chapters/standard_library_strings.htmlGnat wants FOUR params ... and it's the last "map" related
one that's most mysterious. I'd also seen examples using
only TWO params ... but the compiler balks.
In any case :
Idx := Index
(Source => S,
Pattern => P,
From => Idx + 1);
won't compile no matter what you put in "from".
Gnat wants FOUR params ... and it's the last "map" related
one that's most mysterious. I'd also seen examples using
only TWO params ... but the compiler balks.
In any case :
Idx := Index
(Source => S,
Pattern => P,
From => Idx + 1);
won't compile no matter what you put in "from".
and lists 6 functions named Index (and 2 for Index_Non_Blank). Of these I
mostly use the one at paragraph 9:
9 function Index (Source : in String;
Pattern : in String;
Going : in Direction := Forward;
Mapping : in Maps.Character_Mapping >> := Maps.Identity)
return Natural;
with the defaults for the last 2 parameters. Occasionally I've used a Going =>
Backward,
I'm using unbounded strings and there's a version in
that library with the same params - but Gnat seems
to DEMAND the last two params. Might try the fixed
library by casting my unbounded to string ...
I've been programming since a tad before the dawn of the
Apples and Commodores - punch cards and serial terminals
wired to the mini-mainframe, FORTRAN, COBOL, that horrible
stuff. For some reason I just can't grock a lot of the Ada
docs. Lots and lots of DESCRIPTIONS about how to do things
but a "picture" is worth a thousand words ...
Gnat wants FOUR params ... and it's the last "map" related
one that's most mysterious. I'd also seen examples using
only TWO params ... but the compiler balks.
In any case :
Idx := Index
(Source => S,
Pattern => P,
From => Idx + 1);
won't compile no matter what you put in "from".
On 2022-01-07 03:41, 1.AAC0832 wrote:
and lists 6 functions named Index (and 2 for Index_Non_Blank). Of
these I mostly use the one at paragraph 9:
9 function Index (Source : in String;
Pattern : in String;
Going : in Direction := Forward;
Mapping : in Maps.Character_Mapping
:= Maps.Identity)
return Natural;
with the defaults for the last 2 parameters. Occasionally I've used a
Going => Backward,
I'm using unbounded strings and there's a version in
that library with the same params - but Gnat seems
to DEMAND the last two params. Might try the fixed
library by casting my unbounded to string ...
I missed that detail in your original msg. Ada.Strings.Unbounded (ARM
A.4.5) has similar Index functions, but note that Source is
Unbounded_String and Pattern is String. As Brukardt said, without more
detail we can't tell what is really going on, but my experience is that
GNAT will not require defaulted parameters. More likely GNAT is trying
to do overload resolution when there is no visible subprogram that
matches the parameters you are passing; the resulting error msgs are not clear.
Experienced Ada users find that Unbounded_String is needed a lot less
than is expected by people coming from languages where strings are
magic. Unless you need data structures with varying-length strings, you
don't often need them.
I've been programming since a tad before the dawn of the
Apples and Commodores - punch cards and serial terminals
wired to the mini-mainframe, FORTRAN, COBOL, that horrible
stuff. For some reason I just can't grock a lot of the Ada
docs. Lots and lots of DESCRIPTIONS about how to do things
but a "picture" is worth a thousand words ...
I also started out with FORTRAN-66 on punched cards, but my experience
is the opposite: Ada (without the features that were mistakes) supports
very well the way I engineer S/W.
"1.AAC0832" <z24ba7.net> wrote in message news:AOmdnX_3T5ObO0r8nZ2dnUU7-IHNnZ2d@earthlink.com...
...
Gnat wants FOUR params ... and it's the last "map" related
one that's most mysterious. I'd also seen examples using
only TWO params ... but the compiler balks.
In any case :
Idx := Index
(Source => S,
Pattern => P,
From => Idx + 1);
won't compile no matter what you put in "from".
I use this sort of thing all the time (especially in the Trash-Finder spam filter), and it works fine. You never have to give the 4th parameter in
these routines as they have a defined default which allows you to omit them. So it's highly likely that you've done something else wrong which is why nothing you try works.
But you've given so little detail about your program, it's impossible to help. Ada resolution can be finiky, especially when a routine is overloaded as Index is, and that is also the case where it is difficult/impossible for
a compiler to give an understandable error message. To get useful help
around here, you need to provide a complete example (including all of the declarations and use clauses and with clauses). Otherwise, it just ends up being griping and people will tune you out.
For instance, in the above, I have no idea what types S, P, and Idx have -- and that matters a lot -- Ada is a very strongly typed language.
Randy.
On 07.01.22 03:31, 1.AAC0832 wrote:
Gnat wants FOUR params ... and it's the last "map" related
one that's most mysterious. I'd also seen examples using
only TWO params ... but the compiler balks.
In any case :
Idx := Index
(Source => S,
Pattern => P,
From => Idx + 1);
won't compile no matter what you put in "from".
In case you use the opaque type Unbounded_String everywhere,
and then the Index function, it is documented to want a String,
not an Unbounded_String for the Pattern. So, if that's the case,
get a normal (fixes size array) String from an Unbounded_String
object first.
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
function pos2 (hay_stack : Unbounded_String; needle : Unbounded_String)
return Natural
is
result : Natural;
begin
result := Index (Source => hay_stack,
Pattern => To_String(needle),
From => 2);
return result;
end pos2;
Hate typing long things ... made one-liners S2U() and
U2S() if you can guess what those are :-)
This group is so packed with spam that I wondered if anybody real
still used it.
Hate typing long things ... made one-liners S2U() and
U2S() if you can guess what those are :-)
This is totally line with the strict typing of Ada (no implicit conversion). Most of us abbreviate even more as "+".
Sorry, but I fail to see any reason the standard Ada.Strings Index functions would not work for your usecases. If possible please provide a succint explanation.
"1.AAC0832" <z24ba7.net> writes:
This group is so packed with spam that I wondered if anybody real
still used it.
I was going to say "what?" but if I look via Google Groups I see what
you mean. Just had a merry few minutes marking posts as abuse.
On 1/10/22 10:05 AM, Simon Wright wrote:
"1.AAC0832" <z24ba7.net> writes:
This group is so packed with spam that I wondered if anybody real
still used it.
I was going to say "what?" but if I look via Google Groups I see what
you mean. Just had a merry few minutes marking posts as abuse.
Heh heh ... welcome to the underlying reality. Taking
the red pill has consequences :-)
On 2022-01-11 7:17, 1.AAC0832 wrote:
On 1/10/22 10:05 AM, Simon Wright wrote:
"1.AAC0832" <z24ba7.net> writes:
This group is so packed with spam that I wondered if anybody real
still used it.
I was going to say "what?" but if I look via Google Groups I see what
you mean. Just had a merry few minutes marking posts as abuse.
Heh heh ... welcome to the underlying reality. Taking
the red pill has consequences :-)
So use comp.lang.ada through the Real(tm) USENET instead of Google Groups.
This group is not moderated, so there are occasional "meet the girls"
posts, but not enough to be troublesome.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 335 |
Nodes: | 16 (2 / 14) |
Uptime: | 149:28:09 |
Calls: | 7,411 |
Calls today: | 1 |
Files: | 12,670 |
Messages: | 5,613,198 |