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,FREEMAIL_FROM autolearn=ham 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!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mart van de Wege Newsgroups: comp.lang.ada Subject: Re: Beginners question: Compound types, how-to? Date: Mon, 01 Nov 2010 14:05:02 +0100 Message-ID: <86bp695h4x.fsf@gareth.avalon.lan> References: <86wroy58ff.fsf@gareth.avalon.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net dWj0iRv1ZNZimX3wZAMGuwSag2Yc+Pbe/GD8lctytv4Gf9RyCi X-Orig-Path: gareth.avalon.lan!not-for-mail Cancel-Lock: sha1:eHf2sEN2zCEmPoxUeb6p5Rfij3A= sha1:SwHFZuNR38UMpKtmy/bNQWmlTSM= User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Xref: g2news2.google.com comp.lang.ada:16071 Date: 2010-11-01T14:05:02+01:00 List-Id: Brian Drummond writes: > 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). In fact, this particular problem domain calls for inheritance, with a generic Creature type defining the basic attributes and operations, and Player_Character, Non_Player_Character and a Monster derived types. Which is why I said that I am going to refactor that sooner or later anyway. > 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". > Str = Strength. As Florian said, those are domain-specific abbreviations. Anyone who plays role-playing games will know what they mean, anyone who doesnt doesn't have any use for my code anyway. In fact, I suspect once I'm done I'm the only one to have any use for it, but hobby projects like these are always fun to learn a language with; my previous implementation (which works), was done in Perl/Moose, to learn that particular framework. Mart -- "We will need a longer wall when the revolution comes." --- AJS, quoting an uncertain source.