comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: using put procedure with a generic package
Date: Thu, 8 May 2008 08:54:56 -0700 (PDT)
Date: 2008-05-08T08:54:56-07:00	[thread overview]
Message-ID: <f01a40ae-c416-49bf-b878-f7841b8829bb@b5g2000pri.googlegroups.com> (raw)
In-Reply-To: f4751dc5-2909-46c3-9dc3-5883f28d8400@56g2000hsm.googlegroups.com

On May 7, 9:48 pm, "ophir.gef...@gmail.com" <ophir.gef...@gmail.com>
wrote:
> On May 8, 7:09 am, "Jeffrey R. Carter"
>
>
>
> <spam.jrcarter....@spam.acm.org> wrote:
> > ophir.gef...@gmail.com wrote:
>
> > > * queues.ads:
> > > with Ada.Text_IO;
> > > generic
> > >   type Item is private;
> > >   with procedure Item_Put(The_Item : in Item);
>
> > Item_Put has exactly one parameter.

> Hi
> Thanks for the quick reply
>
> The problem is that the package needs to know how to handle most non-
> limited types like Integer, String, Client, Plane, Book, Document, ...
> The Put procedure in any of those might and should be different from
> Put Integer.
>
> And I don't want to force the package user to declare a special Put
> procedure with only one var.

I think you should anyway, even if you think you don't want to.  The
generic is defined correctly; the generic formal subprogram reflects
exactly what you need---an output routine that takes one parameter of
type Item.  In most cases, *somebody* is going to have to define a
routine like that, somewhere.  And if the package that defines, say,
Document, doesn't provide a routine with exactly that profile (maybe
the only Document output routines take page-dimension parameters),
then whoever instantiates your generic is going to have to write a
wrapper routine anyway.  It's pretty common in my experience to have
to write small routines like this for generic instantiation purposes,
and I don't see that changing until they decide to add something like
Lambda expressions to Ada, which I don't think will be happening soon.

In fact, if the Put routines of Integer_IO didn't have default
parameters (so that every time you called Put you would have to
explicitly specify the Width and Base), it would seem normal, and not
particularly burdensome, to write a one-parameter wrapper routine in
order to instantiate the generic.  I think only reason there's an
issue, and that you "don't want to" make the users declare "special"
Put routines, is that Put *looks* like it has just one parameter the
way it's normally used.  But since it doesn't, you're getting this
error which is surprising, and that makes it seem like users are being
forced to do something they shouldn't have to do.  Probably, the
solution is for the compiler to detect this case and display a more
helpful error message, but other than that I don't think this is a
problem.

                                  -- Adam






      parent reply	other threads:[~2008-05-08 15:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-08  3:27 using put procedure with a generic package ophir.geffen
2008-05-08  4:09 ` Jeffrey R. Carter
2008-05-08  4:48   ` ophir.geffen
2008-05-08  7:24     ` Dmitry A. Kazakov
2008-05-08 15:54     ` Adam Beneschan [this message]
replies disabled

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