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,b328eee5522f8a6c X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 11 Jan 2008 20:57:34 -0600 From: "Steve" Newsgroups: comp.lang.ada References: <13oe10uh39g0v85@corp.supernews.com> Subject: Re: [Beginner Problem] Varibles not getting assigned correctly Date: Fri, 11 Jan 2008 19:00:15 -0800 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 Message-ID: X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 24.20.111.206 X-Trace: sv3-yMfOtHltNPpsh5pF+CGbKUW0v7YoUovhk1FkkE+N35YVgKp2WEWi2EWGvh1Q84rNlGNPD5GrkZGNsey!Dx9bK+QeE1ox5ORhx3OowpahlzgXHkIdZN0EpHkMWeJ6TawEMGsX/gUWJu2ChNXdy7EBffWhBwEt!ZPAIXTIiogYCTj+fV5qvYtUoz0ONVQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net 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.37 Xref: g2news1.google.com comp.lang.ada:19335 Date: 2008-01-11T19:00:15-08:00 List-Id: "Shane Smith" wrote in message news:13oe10uh39g0v85@corp.supernews.com... > Hi all, > > I'm trying to write a simple program (that manacla game), I've > encountered a problem where the variables that are used in a nested > procedure can't be assigned a value. I'm using GNAT 4.1.2 on Linux. > Hi. Since you volunteered "beginner" problem I would like to make a suggestion on program structure. When I was in college (a couple of decades ago) where I learned Pascal, one of my instructors had the requirement that no global variables were permitted. Only global types. If you are want to avoid using multiple packages (until you're a little... very little) farther along you can structure the main procedure: procedure Manacala is procedure A( ... args ... ) is begin ... end A; procedure Main is ... variables delclared here .. begin ... code here that passes arguments to other procedures/functions end Main; begin Main; end Manacala; When programs are broken down this way you can understand the operation of a procedure or function based on just the arguments and the type definitions. This makes it easy to understand small pieces of code and how they interact with data. Regards, Steve (The Duck) > ---CODE--- > > procedure Manacla is > > type pits is array (1 .. 14) of Integer; > type Score_Type is array (1 .. 2) of integer; > type arr_point is access pits; > board : arr_point; > > Score1 : Integer := 0; > Score2 : Integer := 0; > Scores : Score_type := (0,0); > Player : Integer range 1 .. 2 := 1; > Winner : integer := 0; > Test : constant integer := 11; > Pit : Integer := 0; > > ... > > procedure Status (Player : in integer) > is > > begin > -- Check if 'playing pits' are empty, if not exit > while board.all(2 .. 7) = (0,0,0,0,0,0) or board.all(9 .. 14) = > (0,0,0,0,0,0) loop > > if Player = 1 then > if board.all(2 .. 7) = (0,0,0,0,0,0) then > Winner := 1; > else exit; > end if; > else > if board.all(9 .. 14) = (0,0,0,0,0,0) then > Winner := 2; > else exit; > end if; > end if; > end loop; > end Status; > > ... > > procedure Player1 > is > Pit : Integer := 0; > Player : Integer := 1; > > begin > ... > Status(Player); > end PLayer1; > > begin > ... > player1; > end Manacla; > > ---END CODE--- > > Basically main body calls player1 and player1 calls status(player) (which > edits the winner variable). > > In gdb 'p winner' gives "$14 = 7270388". > It happens to arrays and access varibles as well.