comp.lang.ada
 help / color / mirror / Atom feed
* Linked List in ada
@ 2002-06-18 23:21 kaak
  2002-06-19  0:50 ` tmoran
  2002-06-19  2:39 ` SteveD
  0 siblings, 2 replies; 9+ messages in thread
From: kaak @ 2002-06-18 23:21 UTC (permalink / raw)


I'm curious about linked lists and pointers in ada. I'm not sure exactly how
they work.

This is the code i have so far:

procedure insertRear(header:in out ptr; x: integer) is

        p: ptr;
        q: ptr;
BEGIN
        p = new node;
        p.key = x;
        q = header;

        loop:
                exit when q.next = null;
                if q.next then
                        q = q.next;
                else
                        exit;
                end if;
        end loop;

        q.next = p

I don't think the syntax is right with the pointers. and ideas?






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-18 23:21 Linked List in ada kaak
@ 2002-06-19  0:50 ` tmoran
  2002-06-19  5:54   ` kaak
  2002-06-19  2:39 ` SteveD
  1 sibling, 1 reply; 9+ messages in thread
From: tmoran @ 2002-06-19  0:50 UTC (permalink / raw)


> I don't think the syntax is right with the pointers. and ideas?
  You're pretty close.  What does your compiler say when you try to
compile it?  That, and looking at running Ada code and seeing how it looks
different, should find the syntax errors.  Semantically, look to see
what's needed and what (like two "exit"s in the loop) is extra garbage.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-18 23:21 Linked List in ada kaak
  2002-06-19  0:50 ` tmoran
@ 2002-06-19  2:39 ` SteveD
  2002-06-19  5:53   ` kaak
  1 sibling, 1 reply; 9+ messages in thread
From: SteveD @ 2002-06-19  2:39 UTC (permalink / raw)


"kaak" <the_kaak@hotmail.com> wrote in message
news:NfPP8.30076$9b.3149846@typhoon.austin.rr.com...
> I'm curious about linked lists and pointers in ada. I'm not sure exactly
how
> they work.
>
> This is the code i have so far:
>
> procedure insertRear(header:in out ptr; x: integer) is
>
>         p: ptr;
>         q: ptr;
> BEGIN
>         p = new node;
>         p.key = x;
>         q = header;
>
>         loop:
>                 exit when q.next = null;
>                 if q.next then
>                         q = q.next;
>                 else
>                         exit;
>                 end if;
>         end loop;
>
>         q.next = p
>
> I don't think the syntax is right with the pointers. and ideas?
>
Here are a few hints:
  In Ada assignment is done with the ":=" operator not "=".
  The only value permitted as the condition of an if statement is an
expression that evaluates to a boolean.
  Labels end with a colon, the beginning of a loop does not.
  If you try compiling the program, most compilers will direct you to these
simple errors.
  If your program is small, go ahead and post a working example, you'll
generally get a better response that way.  If your program is large, try
creating a small version that reproduces just the part you have in question.

SteveD






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-19  2:39 ` SteveD
@ 2002-06-19  5:53   ` kaak
  0 siblings, 0 replies; 9+ messages in thread
From: kaak @ 2002-06-19  5:53 UTC (permalink / raw)


thanks :)


"SteveD" <nospam_steved94@attbi.com> wrote in message
news:1aSP8.91747$6m5.78798@rwcrnsc51.ops.asp.att.net...
> "kaak" <the_kaak@hotmail.com> wrote in message
> news:NfPP8.30076$9b.3149846@typhoon.austin.rr.com...
> > I'm curious about linked lists and pointers in ada. I'm not sure exactly
> how
> > they work.
> >
> > This is the code i have so far:
> >
> > procedure insertRear(header:in out ptr; x: integer) is
> >
> >         p: ptr;
> >         q: ptr;
> > BEGIN
> >         p = new node;
> >         p.key = x;
> >         q = header;
> >
> >         loop:
> >                 exit when q.next = null;
> >                 if q.next then
> >                         q = q.next;
> >                 else
> >                         exit;
> >                 end if;
> >         end loop;
> >
> >         q.next = p
> >
> > I don't think the syntax is right with the pointers. and ideas?
> >
> Here are a few hints:
>   In Ada assignment is done with the ":=" operator not "=".
>   The only value permitted as the condition of an if statement is an
> expression that evaluates to a boolean.
>   Labels end with a colon, the beginning of a loop does not.
>   If you try compiling the program, most compilers will direct you to
these
> simple errors.
>   If your program is small, go ahead and post a working example, you'll
> generally get a better response that way.  If your program is large, try
> creating a small version that reproduces just the part you have in
question.
>
> SteveD
>
>
>





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-19  0:50 ` tmoran
@ 2002-06-19  5:54   ` kaak
  2002-06-19  7:46     ` tmoran
  2002-06-20  1:58     ` SteveD
  0 siblings, 2 replies; 9+ messages in thread
From: kaak @ 2002-06-19  5:54 UTC (permalink / raw)


Well, i haven't tried to compile it yet. I am anti error msgs :) I will get
it though, I've been looking at ada syntax on the web...trying to program in
a language you don't know isn't all that easy ;)







^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-19  5:54   ` kaak
@ 2002-06-19  7:46     ` tmoran
  2002-06-19 16:10       ` Mark Johnson
  2002-06-20  1:58     ` SteveD
  1 sibling, 1 reply; 9+ messages in thread
From: tmoran @ 2002-06-19  7:46 UTC (permalink / raw)


> Well, i haven't tried to compile it yet. I am anti error msgs :)
  You need to get your mind turned around.  An Ada compiler is not
just a necessary step to producing machine code, it's an assistant
helping you avoid error and get your program right.  Think of
every compiler error message as a run-time error avoided.  Sometimes
the compiler does seem just picky - "of course I *meant* an
assignment statement there, not an equality test, stupid compiler",
but other times you'll say, "oops, you're right.  I didn't really
mean to increment the counter by q, I meant to increment by q.x".
And sometimes you'll think the compiler is being terribly obstructionist
and refusing all variants of what you want to do.  In that situation,
sit back and think and you'll probably find that what you were trying
to do was fundamentally a bad idea and you should be doing it some
other way entirely.  You need to think of the Ada compiler as your
helper, and the only way it can talk to you is via "error" messages.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-19  7:46     ` tmoran
@ 2002-06-19 16:10       ` Mark Johnson
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Johnson @ 2002-06-19 16:10 UTC (permalink / raw)


tmoran@acm.org wrote:
> 
> > Well, i haven't tried to compile it yet. I am anti error msgs :)
>   You need to get your mind turned around.  An Ada compiler is not
> just a necessary step to producing machine code, it's an assistant
> helping you avoid error and get your program right.  [snip...]

Hmm. Let me provide a different opinion on that recommendation. If you
use the compiler as a quality check on your code review, you can get a
better quality product and better productivity. I might even recommend
this strongly to the OP since it encourages good habits (stronger code
review). Let me explain how that can work...

If you have generated say 20 defects in a program and have two people do
the compile and code review you might get the following results...
  #1 - compile flags 12 errors, code review removes 4 more (total 16), 4
left to find in unit test.
  #2 - compile flags 12 errors, code review removes 6 more (total 18), 2
left to find in unit test.
Now do them in the other order...
  #1 - code review removes 10 errors, compiler flags 6 more (total 16),
4 left to find in unit test.
  #2 - code review removes 15 errors, compiler flags 3 more (total 18),
2 left to find in unit test.
That the compiler found 6 instead of 3 errors for #1 is an indication
that the code review was poor and should be repeated.

The counter argument is usually that the compiler finds the errors
faster than you do. I agree, but the cost of letting the two extra
errors in unit test (say 1 hour to find and fix each) more than pays for
the longer code review cycle.
  --Mark



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-19  5:54   ` kaak
  2002-06-19  7:46     ` tmoran
@ 2002-06-20  1:58     ` SteveD
  2002-06-20  6:50       ` Adrian Hoe
  1 sibling, 1 reply; 9+ messages in thread
From: SteveD @ 2002-06-20  1:58 UTC (permalink / raw)


In case you haven't found it, the site www.adapower.com has a lot of good
resources.  Including links to books that are available free on the web.

SteveD

"kaak" <the_kaak@hotmail.com> wrote in message
news:B0VP8.31233$9b.3950675@typhoon.austin.rr.com...
> Well, i haven't tried to compile it yet. I am anti error msgs :) I will
get
> it though, I've been looking at ada syntax on the web...trying to program
in
> a language you don't know isn't all that easy ;)
>
>
>
>





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Linked List in ada
  2002-06-20  1:58     ` SteveD
@ 2002-06-20  6:50       ` Adrian Hoe
  0 siblings, 0 replies; 9+ messages in thread
From: Adrian Hoe @ 2002-06-20  6:50 UTC (permalink / raw)


SteveD wrote:

> In case you haven't found it, the site www.adapower.com has a lot of good
> resources.  Including links to books that are available free on the web.
> 
> SteveD
> 
> "kaak" <the_kaak@hotmail.com> wrote in message
> news:B0VP8.31233$9b.3950675@typhoon.austin.rr.com...
> 
>>Well, i haven't tried to compile it yet. I am anti error msgs :) I will
>>
> get
> 
>>it though, I've been looking at ada syntax on the web...trying to program
>>
> in
> 
>>a language you don't know isn't all that easy ;)
>>
>>
>>
>>
>>
> 
> 



I have a polymorphic bi-direction linked list with examples at my 
website. It is easy to understand.

-- 
Remove *nospam* to email.              -- Adrian Hoe
                                        -- http://adrianhoe.com





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2002-06-20  6:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-18 23:21 Linked List in ada kaak
2002-06-19  0:50 ` tmoran
2002-06-19  5:54   ` kaak
2002-06-19  7:46     ` tmoran
2002-06-19 16:10       ` Mark Johnson
2002-06-20  1:58     ` SteveD
2002-06-20  6:50       ` Adrian Hoe
2002-06-19  2:39 ` SteveD
2002-06-19  5:53   ` kaak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox