From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,NICE_REPLY_A, URI_TRY_3LD autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!buffer2.nntp.dca1.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 06 Jan 2022 20:31:34 -0600 Subject: Re: Ok - WHAT are those "Maps.Identity" things ??? Newsgroups: comp.lang.ada References: From: "1.AAC0832" Date: Thu, 6 Jan 2022 21:31:33 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 98.77.165.67 X-Trace: sv3-EET3+qSSJoybR8aW95XxDbJ4YOdSGiY+vHbX6BpwBwaTgwlDFMd90tNhFWmqze9r6ywioWR5CaPOiOw!Css48xW8QZx/LmYbvJhq2BVQT/manKS8JL6vMwKf3aZ3nAckMWWx8u9F3FLJpM3WJ8ZDbUFlHdAL!sXnTu/x0o42t7ayi4qA= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4748 Xref: reader02.eternal-september.org comp.lang.ada:63349 List-Id: 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,,) >> >> 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.