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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5e9097cf4f3eaf57 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.125.233 with SMTP id mt9mr3685020pbb.5.1333646646959; Thu, 05 Apr 2012 10:24:06 -0700 (PDT) Path: r9ni22100pbh.0!nntp.google.com!news1.google.com!goblin3!goblin1!goblin.stu.neva.ru!news2.euro.net!newsfeed.freenet.ag!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 05 Apr 2012 12:24:05 -0500 User-Agent: NewsTap/3.5.5 (iPad) From: Martin Dowie Newsgroups: comp.lang.ada Mime-Version: 1.0 Message-ID: <514763028355339029.041536martin-re.mo.ve.thedowies.com@news.btinternet.com> Subject: Re: Checking to see if a string is a letter References: Date: Thu, 05 Apr 2012 12:24:05 -0500 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-pmohnznljeu6JEgz7yfmuaFtnoYBfjxIDiDXV121cBhK2VurgF3qcye6axfZ4EMWj6RSz7arYku+daI!BQU61bE6t/9/KMF+R6oRVozD2s0n/aqXNLbDeCQLa5AUJdpCPR9WbaVKruSaFw77ZH5PUGVtLz5K!353d1No4g9xPD8S4YrD+y+QLfTcQMzJln5UeLPGc/3STsFdh X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com 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: 3632 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 2012-04-05T12:24:05-05:00 List-Id: deuteros wrote: > On Tue 03 Apr 2012 04:26:40a, Simon Wright wrote in > news:m2k41xi5kv.fsf@pushface.org: > >> deuteros writes: >> >>> On Tue 03 Apr 2012 01:15:27a, Jeffrey Carter >>> wrote in >>> news:jle13q$ale$1@tornado.tornevall.net: >>> >>>> What do you mean by "contains a single letter"? >>> >>> I mean the string contains a single letter and nothing more. For >>> example: >>> >>> a - Legal >>> A - Legal >>> aa - Illegal >>> a1 - Illegal >> >> Then for a start the length of the string needs to be 1. >> >> If it is, the first (and only!) character needs to be a lower- or >> upper-case letter. There are (at least) three ways of doing this: >> >> * declare an array of Boolean indexed by Character, with the elements >> indexed by letters set to True and the others to False, and index by >> the character to be tested; >> >> * declare two subtypes of character ("Character range 'a' .. 'z'", for >> instance) and check whether the character to be tested is 'in' either >> of the subtypes; >> >> * use the standard library, Ada.Characters.Handling.Is_Letter (probably >> the easiest for you!) > > Alright, here's my function: > > function isVariable(token: in String) return Boolean is > ParserException : Exception; > begin > if(token'Length = 1) then > return (Is_Letter(token(1))); > end if; > > raise ParserException with ("Not a letter : " & token); > > end isVariable; > > But I'm getting this warning: > > warning: index for "token" may assume lower bound of 1 > warning: suggested replacement: "token'First + -1" See http://www.ada-auth.org/standards/12rm/html/RM-3-6-3.html to see how String is defined. >From this you can see that token may not have a value at "token (1)", perhaps it is indexed by 10..20. If you know that all the strings you'll ever pass to this function will start with an index = 1, then you could add a "pragma Assert (tokenFirst = 1);" at the start of the declarative part. An exception will then be raised if this isn't true (assuming the correct compiler switches are selected). NB: ParserException is declared locally, so isn't visible to any subprogram that could attempt to catch it...you'd need to use "when others =>". HTH -- Martin -- -- Sent from my iPad