comp.lang.ada
 help / color / mirror / Atom feed
* Need help with code?
@ 1997-12-10  0:00 Eric Sabo
  1997-12-14  0:00 ` Chris Morgan
  1997-12-15  0:00 ` Simon Wright
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Sabo @ 1997-12-10  0:00 UTC (permalink / raw)



Can someone tell what am I doing wrong with this code?
----------------------- begin ----------------------------------------
generic
 type item_type is private;
procedure push(x : in out item_type);
procedure push(x : in out item_type) is
  type item_node;
  type item_ptr is access item_node;
  record
 item : item_type;
        next : item_ptr;
  end record;
  temp : item_type;
  first, last, p : item_ptr := null;
begin
   put("Enter data (null to quit)");
        get(temp);
    while temp /= null loop
  p := new item_node;
    p.item := temp;
   p.next := null;
  if first = null then
   first := p;
   last := p;
  else
   last.next := p;
   last := p;
  end if;
 put("Enter data (null to quit)");
        get(temp);
 end loop;
end push;
generic
 type item_type is private;
procedure print(x : in out item_type);
procedure print(x : in out item_type) is
  type item_node;
  type item_ptr is access item_node;
  record
 item : item_type;
        next : item_ptr;
  end record;
  first, last, p : item_ptr;
begin
  put_line("Here is the stack you requested");
 p := first;
 while p /= null loop
  put(p.number);
  put(" ");
  p := p.next;
        end loop;
end print;
generic
 type item_type is private;
procedure pop(x : in out item_type);
procedure pop(x : in out item_type) is
  type item_node;
  type item_ptr is access item_node;
  record
 item : item_type;
        next : item_ptr;
  end record;
  first, last, p : item_ptr;
begin
 put_line("Popping the first item of the linked list");
        p := first.next;
        first := p;
end pop;
with push;
with pop;
with print;
with gnat.io; use gnat.io;
procedure maingeneric is
-- integer type
type item_integer;
type int_ptr is access item_integer;
record
 a : integer;
        next : int_ptr;
end record;
procedure int_push is new push(item_integer);
procedure int_pop is new pop(item_integer);
procedure int_print is new print(item_integer);
-- float type
type item_float;
type flt_ptr is access item_float;
record
 f : float;
 next : flt_ptr;
end record;
procedure flt_push is new push(item_float);
procedure flt_pop is new pop(item_float);
procedure flt_print is new print(item_float);
-- record type
type item_rec;
type rec_ptr is access item_rec;
record
 name : string (1..20);
 id : string(1..10);
 next : rec_ptr;
end record;
procedure rec_push is new push(item_rec);
procedure rec_pop is new pop(item_rec);
procedure rec_print is new print(item_rec);
begin
 push(a);
        push(f);
 push(name);
end maingeneric;
------------------- end  --------------------------------

thanks,
Eric Sabo
sabo@hhs.net
sab9074@cup.edu






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

* Re: Need help with code?
  1997-12-10  0:00 Need help with code? Eric Sabo
@ 1997-12-14  0:00 ` Chris Morgan
  1997-12-15  0:00 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Morgan @ 1997-12-14  0:00 UTC (permalink / raw)




Not enough comments for a start!

Chris

"Eric Sabo" <sabo@hhs.net> writes:

> 
> Can someone tell what am I doing wrong with this code?
> ----------------------- begin ----------------------------------------
> generic
>  type item_type is private;

-- 
Chris Morgan <mihalis at ix.netcom.com>
     "I'm considering throwing myself out of the window.  It
      wouldn't do me much damage because we're on the ground 
      floor, but it might make for a bit of variety."  - Lizzy Bryant




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

* Re: Need help with code?
  1997-12-10  0:00 Need help with code? Eric Sabo
  1997-12-14  0:00 ` Chris Morgan
@ 1997-12-15  0:00 ` Simon Wright
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Wright @ 1997-12-15  0:00 UTC (permalink / raw)



"Eric Sabo" <sabo@hhs.net> writes:

> Can someone tell what am I doing wrong with this code?
> ----------------------- begin ----------------------------------------
> generic
>  type item_type is private;
> procedure push(x : in out item_type);
> procedure push(x : in out item_type) is
>   type item_node;
>   type item_ptr is access item_node;
    type item_node is                        <<<<<<<<<<<
>   record
>  item : item_type;
>         next : item_ptr;
>   end record;

and again, about 6 times altogether. I found these fairly easily while
using gnatchop to split your source up into individual files .. and
then there are some more problems with the code (eg, at the end you're
calling the generic push rather than the instantiated rec_push or
whatever) .. and why have you separated push, pop etc into separate
generic subprograms rather than making them members of one generic
{stack? list? what?} package?

I think you (and we) would find it a lot easier to see what you were
about if you would lay your code out neatly. I don't know what editor
you're using, emacs has a neat auto-indent feature. If you don't have
such an editor, it's often worth closing the structure before putting
in the contents; eg,

(stage 1)
  begin

(stage 2)
  begin
  end;

(stage 3)
  begin
    stuff ..
  end;

-- 
Simon Wright                        Work Email: simon.j.wright@gecm.com
GEC-Marconi Radar & Defence Systems            Voice: +44(0)1705-701778
Command & Information Systems Division           FAX: +44(0)1705-701800




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

end of thread, other threads:[~1997-12-15  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-10  0:00 Need help with code? Eric Sabo
1997-12-14  0:00 ` Chris Morgan
1997-12-15  0:00 ` Simon Wright

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