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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e55245590c829bef X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!217.73.144.45.MISMATCH!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: Mon, 01 Nov 2010 06:54:13 -0500 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Beginners question: Compound types, how-to? Date: Mon, 01 Nov 2010 12:03:30 +0000 Reply-To: brian@shapes.demon.co.uk Message-ID: References: <86wroy58ff.fsf@gareth.avalon.lan> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-bAfX19E2rKAbqOZdKcIEBFoHfGVAE8op28YTBeKQ1qm1tYVez48C27O0qparngyxlx8xzYHBfxvp35S!V74ssWpt/yjKIcGlqViO+FD4FZu156ORA0HcZaJcWYT4Soi1vBBa2geCzU1Pm60857bXfX7j0gXL!yb4= 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: 2759 Xref: g2news2.google.com comp.lang.ada:16068 Date: 2010-11-01T12:03:30+00:00 List-Id: On Sun, 31 Oct 2010 23:00:52 +0100, Mart van de Wege wrote: >Hi, > >I've been playing around with Ada for a bit, and like it. To teach it to >myself, I am rewriting some Perl code I wrote for hobby purposes, yet I >can't seem to get my head around how to use compound types. > >I have the following code (yes, I'm an RPG geek, sorry): > type Ability_Type is (Str, Dex, Con, Int, Wis, Cha); > type Character is > record >What am I doing wrong? I am misunderstanding something, but what? C >should be a record containing an Ability_Array as its first field, so I >should be able to index into it using an Ability_Type subscript. How do >I do this? Others have pointed out the syntactic problem here, and the way to resolve it by name qualification. I would suggest that perhaps "Player" would be a better name than "Character" (or perhaps "Actor" if a game player can control several actors). When you read the code in six months and see "Character" you are likely to think "A,B,C" etc. The extra effort to overcome that is unnecessary, and detracts from the work. Likewise Str ... String? Strength? Strangeness? Write them in full; you'll thank yourself later. If you don't like typing long words, either find an editor with an autocomplete function, or learn to use "renames". -- this can be shortened if you have "use"d the package Dex : Games.RPG.DnD.Ability_Type renames Games.RPG.DnD.Dextrose; -- or was it Dexterity? now you can use Dex in a context where there will be no confusion; and refer to the "renames" clause if you get confused anyway... - Brian