Article View: comp.lang.misc
Article #447Ada Generics (was Which language to teach first?)
From: Charles Lindsey
Date: Wed, 09 Aug 1989 10:19
Date: Wed, 09 Aug 1989 10:19
41 lines
1908 bytes
1908 bytes
In article <6204@hubcap.clemson.edu> billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu writes:
(speaking about how difficult it was to program in Pascal, as opposed to Ada)
> .......................................................... What about
> the joy of writing code to manipulate a linked list for the 348th time
> because you can't express it cleanly, once and for all, using generics?
>
But how DO you manipulate linked lists in Ada using Generics?
Suppose I want to write a simple procedure to find the last element of a
linked list. I try the following:
generic
type T is private;
type LINK;
type PLINK is access LINK;
type LINK is record
VAL: T;
NEXT: PLINK;
end record;
function FIND_LAST(LIST: PLINK) return PLINK is
declare
TEMP: PLINK := LIST;
begin
if LIST=null then return null
else while TEMP.NEXT/=null
loop TEMP := TEMP.NEXT
end loop;
return TEMP;
end if;
end FIND_LAST;
BUT there are at least two syntactic impossibilities in the generic_part of
that. And even if it had been legal, it would have been a pain to instantiate.
The odd thing is that, if the problem had been to find the last element of an
array, it would have been easy.
Or can someone show me that there IS a way to write FIND_LAST in Ada?
Charles Lindsey
cs.man.ac.uk
Technical Details
Message-ID:
<6448@ux.cs.man.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!ukc!mucs!r1!chlReferences:
<2552@aplcen.apl.jhu.edu> <6204@hubcap.clemson.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!ukc!mucs!r1!chl From: chl@r1.uucp (Charles Lindsey) Newsgroups: comp.lang.misc Subject: Ada Generics (was Which language to teach first?) Summary: Problems with generic linked lists Keywords: Ada, generic Message-ID: <6448@ux.cs.man.ac.uk> Date: 9 Aug 89 10:19:18 GMT References: <2552@aplcen.apl.jhu.edu> <6204@hubcap.clemson.edu> Sender: news@ux.cs.man.ac.uk Reply-To: chl@cs.man.ac.uk (Charles Lindsey) Organization: University of Manchester, UK Lines: 41