comp.lang.ada
 help / color / mirror / Atom feed
From: sbelmont700@gmail.com
Subject: Re: Passing indefinite types
Date: Tue, 5 Feb 2013 13:16:10 -0800 (PST)
Date: 2013-02-05T13:16:10-08:00	[thread overview]
Message-ID: <1012259e-1325-4121-ac43-c17e5a17d0b9@googlegroups.com> (raw)
In-Reply-To: <5262a822-409a-4c79-a842-0e716527cb70@googlegroups.com>


I had pretty much resigned myself to using the heap anyhow, this was mostly just out of curiosity as to whether it could be done or not.  It seems a shame that it cannot, since there are already mechanisms to safely pass local access values to longer-lived subprograms, so long as their are by themselves or within records.  An array seems like the logical next step.

But in the interests of proving it can actually be done, here is my best take on it: a (completly unreadable) linked list of access-discriminanted records, where the callee would presumably iterate through them as needed.  This would work for limited types, too, whereas (most of?) the normal containers would not.


package k is

   type String_Holder (s : not null access string) is null record;
   
   type Node;
   type Node_Holder (n : not null access Node) is null record;

   type Node (string_data : not null access String_Holder;
              next_node   : access Node_Holder) is null record;
              
   function find (pattern : string;
                  sources : Node) return boolean;
                   
end k;

procedure p is

  s1   : aliased string := "One thing";
  s2   : aliased string := "another thing";
  s3   : aliased string := "third thing";
  
  s1_h : aliased k.string_holder := (s => s1'access);
  s2_h : aliased k.string_holder := (s => s2'access);
  s3_h : aliased k.string_holder := (s => s3'access);

  n3   : aliased k.node := (s3_h'access, null);
  n3_h : aliased k.node_holder := (n => n3'access);
  
  n2   : aliased k.node := (s2_h'access, n3_h'access);
  n2_h : aliased k.node_holder := (n => n2'access);
  
  n1   : k.node := (s1_h'access, n2_h'access);
  
  x : boolean := k.find ("look ma, no heap!", n1);

begin
  null;
end;

Thanks again to everyone for their suggestions.

-sb



      parent reply	other threads:[~2013-02-05 21:16 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
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 [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