From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx17.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:35.0) Gecko/20100101 Thunderbird/35.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: comparing characters in string References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Sun, 05 Oct 2014 00:39:45 UTC Organization: TeraNews.com Date: Sat, 04 Oct 2014 18:41:45 -0700 X-Received-Bytes: 2795 X-Received-Body-CRC: 1361694868 Xref: news.eternal-september.org comp.lang.ada:22092 Date: 2014-10-04T18:41:45-07:00 List-Id: On 10/4/2014 4:03 PM, Stribor40 wrote: > if a'(a'First) = b(b'First + 1) then You're using qualification in that if, which is a semantic error. Qualification is a method to explicitly tell the compiler what type something is, consider having the following functions: Function K return String; Function K return Character; Function J( I : Character ) return String; Function J( I : String ) return String; and the following declaration: Data : String := J(K); Which versions of J and K are used? Well, it's ambiguous, so the compiler is to reject the compilation with an error; but if we had some way to explicitly tell the compiler what type K returns then we would resolve the ambiguity. That is exactly what qualification is/does. Qualification is done with TYPE_NAME'( expression ), so we would resolve the above as follows: Data : String := J( Character'(K) ); -- Forces the K returning a character. If you delete that tick after a, it should compile. if a(a'First) = b(b'First + 1) then But there's a problem with your logic: a'(a'first) and b(b'first + 1) are both constant, so your loop is meaningless. Try: function tt (a, b : in String) return Boolean is Target : Character renames a(a'first); Found : Constant Boolean:= True; Substring : constant String:= b(b'first+1..b'last); begin for Index in substring'range loop if target = Substring(Index) then return Found; end if; end loop; return not Found; end tt; Or, if you're doing Ada 2012: function tt (a, b : in String) return Boolean is Target : Character renames a(a'first); Found : Constant Boolean:= True; Substring : constant String:= b(b'first+1..b'last); begin return (if (for some Ch of Substring => Ch = Target) then Found else not Found); end tt;