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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d142408257dde54c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-30 05:11:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!grolier!freenix!enst!enst.fr!not-for-mail From: Michal Nowak Newsgroups: comp.lang.ada Subject: Re: Can someone help me understand this queue package? Date: Sun, 30 Dec 2001 14:14:56 +0100 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7BIT X-Trace: avanie.enst.fr 1009717862 84550 137.194.161.2 (30 Dec 2001 13:11:02 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Sun, 30 Dec 2001 13:11:02 +0000 (UTC) To: "comp.lang.ada usegroup->mailing list gateway" Return-Path: In-reply-to: X-Mailer: Calypso Version 3.20.01.01 (3) Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.6 Precedence: bulk X-Reply-To: vinnie@inetia.pl List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:18401 Date: 2001-12-30T14:14:56+01:00 On 01-12-29 at 22:02 Liddle Feesh wrote: >"Michal Nowak" wrote: > >> "ADA 95: THE CRAFT OF OBJECT-ORIENTED PROGRAMMING" - chapter 11 >> (in particular - 11.4) > >Okay. In the example given from that page - adding a new "Node" or >"Appoinment" would be done using the procedure (in my example) "Add". > >This procedure is listed as follows: > > procedure add (n: in integer; q: in out queue) is > begin > null; -- Do nothing > end add; > >Now - in the example from the site: > > New_Item := new Appointment_Record; > if Current /= null then -- insert after another appointment > New_Item.Next := Current.Next; > Current.Next := New_Item; > else -- insert at start of list > New_Item.Next := Diary.First; > Diary.First := New_Item; > end if; > > >But the problem comes when you think, what is "New_Item"? Is it a function >call? No - it can't be, no parameters. Is it an instance of a record? >Maybe, >but my compiler (OE) throws up the error "Direct name, New_Item is not >visable" leading me to believe that I haven't instantiated the name >somewhere. But what does it instantiate to? And surely when setting up >"New_Item", you want to fill it with data - which happens in the example >above. But how can you fill it with data when it doesn't exist...? > >Even if I wrote: > >New_Item := new Node; > >This would still fall over with the same error. Here is your package spec: ------------------------------- package queue_package is TYPE queue is LIMITED PRIVATE; empty_queue : EXCEPTION; -- !! FIRST ERROR REPORTED HERE -- !! SECOND ERROR REPORTED HERE procedure initialise (q: in out queue); function is_empty_queue (q: queue) return boolean; procedure add(n: in integer; q: in out queue); procedure remove(n: out integer; q: in out queue); --remove raises the exception "empty-queue" if applied to an empty queue PRIVATE TYPE node; TYPE link is ACCESS node; --ACCESS is a pointer type TYPE node is RECORD value : integer; next : link :=NULL; END RECORD; TYPE queue is RECORD head : link; tail : link; END RECORD; END queue_package; ---------------------------- Look at the line where you defined access type to node (you even marked it with comment). You had errors, because you did not declared a variable of this type. Try now: > procedure add (n: in integer; q: in out queue) is New_Item : Link; --declare a variable of link type > begin New_Item := new node; --now set appriopriate fields in New_Item, --set Head and Tail for queue, and should be OK. > null; -- Do nothing > end add; > >How do I create a new node, and point the 'next' value to the 'value' of >the >next node? I know how this is done on paper... link is access type to node. So speaking in C language, it should point to element of type node. In your queue you have components Head and Tail, that should point to first and last element in the queue. They are of the same type as New_Item is. So: New_Item.Next := Tail; --next points you to element, which is still --considered to be on the end of the queue Tail := New_Item; --now the last element is the one you created. Was that helpful? Mike ----------------------------------------- ____| \%/ |~~\ O | o>> Mike Nowak | T | / > vinnie@inetia.pl | http://www.geocities.com/vinnie14pl _|__