comp.lang.ada
 help / color / mirror / Atom feed
From: "1.AAC0832" <z24ba7.net>
Subject: Re: Ok - WHAT are those "Maps.Identity" things ???
Date: Thu, 6 Jan 2022 21:31:33 -0500	[thread overview]
Message-ID: <AOmdnX_3T5ObO0r8nZ2dnUU7-IHNnZ2d@earthlink.com> (raw)
In-Reply-To: <sr3bi3$fu2$1@dont-email.me>

On 1/5/22 12:49 AM, Rod Kay wrote:
> 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 


   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".

   Oh well, I actually wrote my own. It works just fine
   and I was able to finish what I had in mind. Progressive
   slices of the source string compared against the "needle"
   string with "unbounded_slice" as the cutter-upper. DID
   do a quick pre-scan to see if at least the first char of
   the needle appears in the source and where. We start
   slicing from there, which saves iterations.



> ... 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;> 


   None of my strings are fixed. Those get "stuck" in
   size the first time you assign them and are mostly
   useless IMHO. Tried to use the library with "to_string()"
   but still no joy.

   Anyway, thanks for the input - I'll try a few suggested
   variations from your docs. For now though it's back to
   Lazarus/FPC for a different practical project - the
   kind they pay you for  :-)

   I'm not gonna buy $100 books for a language I was only
   curious about. Adaic seems to have some fair online
   info though.


>     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.

  reply	other threads:[~2022-01-07  2:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-05  0:54 Ok - WHAT are those "Maps.Identity" things ??? 1.AAC0831
2022-01-05  5:49 ` Rod Kay
2022-01-07  2:31   ` 1.AAC0832 [this message]
2022-01-07  3:39     ` Gautier write-only address
2022-01-07  4:14     ` Randy Brukardt
2022-01-10  5:13       ` 1.AAC0832
2022-01-10 10:19         ` Marius Amado-Alves
2022-01-11  5:20           ` 1.AAC0832
2022-01-07 11:48     ` G.B.
2022-01-10  4:49       ` 1.AAC0832
2022-01-05 13:01 ` Jeffrey R.Carter
2022-01-07  2:41   ` 1.AAC0832
2022-01-07  9:49     ` Jeffrey R.Carter
2022-01-10  4:46       ` 1.AAC0832
2022-01-10 15:05         ` Simon Wright
2022-01-11  5:17           ` 1.AAC0832
2022-01-11 11:33             ` Niklas Holsti
2022-01-12  4:22               ` 1.AAC0832
replies disabled

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