comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Re: Passing indefinite types
Date: Sun, 3 Feb 2013 17:25:39 -0800 (PST)
Date: 2013-02-03T17:25:39-08:00	[thread overview]
Message-ID: <8d39b2ad-dc6c-4492-bc43-d2d01d748efa@googlegroups.com> (raw)
In-Reply-To: <85ip696nlk.fsf@stephe-leake.org>

On Sunday, February 3, 2013 5:26:15 PM UTC-5, Stephen Leake wrote:
> 
> Could you show some almost legal code?
> 

I have found several occasions where this is useful (mostly for dealing with classwide types in constructing functions), but for an example consider something more straightforward:  Suppose you want to write a subprogram that searches for a string pattern within an unconstrained number of other strings (and also suppose for the sake of argument that you cannot implement it as multiple calls to a subprogram that searches within a single string).  Since you can't have "ragged" arrays of indefinite types, you try an array of pointers:

package k
  type p is access all string;
  type a is array (positive range <>) of p;
  function find (p: string, sources : a) return boolean;
end k;

But you can't ever call this from a subprogram with locally declared strings, since trying to create p.a with local strings fails the accessibility check.  You can use heap values or unchecked_access, but that's ugly and ought to be unecessary, since the subprogram is not doing anything sketchy with the values.

You can't have an unconstrained number of access discriminants (or access parameters), and trying to 'wrap' each local value fails as well:

package k
  type p (s : access string) is null record;
  type a is array (positive range <>) of p;  --illegal!
  function find (p: string, sources : a) return boolean;
end k;

This is the most aggrevating, because p (in this case) is not actually indefinite, and is always a single, fixed-size (coextensions notwithstanding, but I don't dare look down that rabbit hole).

Even when the number is fixed, but sufficiently large, normal parameters are unwieldly.  For instance:

function find (p: string, source1 : string;
                          source2 : string;
                          <snip>
                          source451 : string) return boolean;
 
> 
> I wonder if it would be possible to write an aspect or other constraint
> 
> that asserts "no pointers are copied"?
> 

That's what access discriminats (and to a lesser extent, access parameters) usually work well for, but I suppose there is no way to create an unconstrained number of them.  What I would like to see is an aspect that says "this discriminated record is not going to be variant, so it's okay to nest it within records and arrays", so that arrays of 'accessors' are legal.

Thank you (everyone) for the responses.

-sb



  reply	other threads:[~2013-02-04  1:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-02 21:07 Passing indefinite types sbelmont700
2013-02-02 21:31 ` Jeffrey Carter
2013-02-03  0:27   ` sbelmont700
2013-02-03  8:07     ` Dmitry A. Kazakov
2013-02-03 10:22 ` gautier_niouzes
2013-02-03 22:26 ` Stephen Leake
2013-02-04  1:25   ` sbelmont700 [this message]
2013-02-04  3:46     ` Shark8
2013-02-05  2:40     ` Randy Brukardt
2013-02-05 13:01     ` Stephen Leake
2013-02-05 20:56       ` Randy Brukardt
2013-02-05 21:16 ` sbelmont700
replies disabled

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