comp.lang.ada
 help / color / mirror / Atom feed
* How to do Generic function?
@ 1996-04-18  0:00 Robert Gelb
  1996-04-18  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Robert Gelb @ 1996-04-18  0:00 UTC (permalink / raw)


I am trying to create a generic sort function that will accept as input an
array of integers or strings or floats and output that array sorted.  Is
there a way to do it in ADA?

Thanks in advance, 
Robert




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

* Re: How to do Generic function?
  1996-04-18  0:00 How to do Generic function? Robert Gelb
  1996-04-18  0:00 ` Robert Dewar
@ 1996-04-18  0:00 ` Doug Smith
  1996-04-19  0:00 ` Michael Quinn
  2 siblings, 0 replies; 5+ messages in thread
From: Doug Smith @ 1996-04-18  0:00 UTC (permalink / raw)


In article <4l4h1p$g6v@hatathli.csulb.edu>, rgelb@csulb.edu (Robert Gelb) wrote:

> I am trying to create a generic sort function that will accept as input an
> array of integers or strings or floats and output that array sorted.  Is
> there a way to do it in ADA?
> 
> Thanks in advance, 
> Robert

I don't do other people's homework when I can help it. But here is a
challenge:

  Implement the following generic and demonstrate a working instantiation:

  generic
    type Index is (<>); -- Usually an index into an array
    with procedure Less_Than (Left, Right : in Index); -- Compares array
elements
    with procedure Swap      (Left, Right : in Index); -- Swaps array elements
  procedure Sort (Starting_At : in Index := Index'First;
                  Ending_At   : in Index := Index'Last);

Doug.

-  -  -  -  -  -  -  -  -  -  -  -  -  v  -  -  -  -  -  -  -  -
Doug Smith                             | 703-760-0519 (Work)
dsmith@clark.net                       | 703-742-8662 (Home)
AdaSmith@ACM.org                       | 703-742-9580 (Fax/Data)
http://www.clark.net/pub/dsmith/       | 168.143.0.120 (NetPhone)




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

* Re: How to do Generic function?
  1996-04-18  0:00 How to do Generic function? Robert Gelb
@ 1996-04-18  0:00 ` Robert Dewar
  1996-04-20  0:00   ` Robert Gelb
  1996-04-18  0:00 ` Doug Smith
  1996-04-19  0:00 ` Michael Quinn
  2 siblings, 1 reply; 5+ messages in thread
From: Robert Dewar @ 1996-04-18  0:00 UTC (permalink / raw)


Robert Gelb says

"I am trying to create a generic sort function that will accept as input an
array of integers or strings or floats and output that array sorted.  Is
there a way to do it in ADA?"

As no doubt are your classmates working on the same assigment?
But perhaps they will write theirs in Ada instead!





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

* Re: How to do Generic function?
  1996-04-18  0:00 How to do Generic function? Robert Gelb
  1996-04-18  0:00 ` Robert Dewar
  1996-04-18  0:00 ` Doug Smith
@ 1996-04-19  0:00 ` Michael Quinn
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Quinn @ 1996-04-19  0:00 UTC (permalink / raw)


rgelb@csulb.edu (Robert Gelb) wrote:

>I am trying to create a generic sort function that will accept as input an
>array of integers or strings or floats and output that array sorted.  Is
>there a way to do it in ADA?

>Thanks in advance, 
>Robert

Yes,  You can create a generic with 2 supplied paramters:

1) a generic fomal type to define your array element type
2) a genric formal function to test for "less than"

Using these two generic parameters you can create a package that will
define your array data types, and your sort function.   Using this
method you may use any data type, as long as you can define an order
that you can test.

Michael T. Quinn
mtquinn@hom.net
   or 
MikeTQuinn@AOL.COM





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

* Re: How to do Generic function?
  1996-04-18  0:00 ` Robert Dewar
@ 1996-04-20  0:00   ` Robert Gelb
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Gelb @ 1996-04-20  0:00 UTC (permalink / raw)


Robert Dewar (dewar@cs.nyu.edu) wrote:
: "I am trying to create a generic sort function that will accept as input an
: array of integers or strings or floats and output that array sorted.  Is
: there a way to do it in ADA?"

:: As no doubt are your classmates working on the same assigment?
:: But perhaps they will write theirs in Ada instead!

	The reason I am asking for help is because I can't figure it out
on my own.
Robert





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

end of thread, other threads:[~1996-04-20  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-18  0:00 How to do Generic function? Robert Gelb
1996-04-18  0:00 ` Robert Dewar
1996-04-20  0:00   ` Robert Gelb
1996-04-18  0:00 ` Doug Smith
1996-04-19  0:00 ` Michael Quinn

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